lists,vectors,dictionaries

New to FreeBASIC? Post your questions here.
Post Reply
zelda64bit
Posts: 27
Joined: Mar 13, 2021 10:18

lists,vectors,dictionaries

Post by zelda64bit »

Hello. I would like to know if in freebasic there are lists, vectors and dictionaries. I was looking at it in the documentation but I didn't see anything.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: lists,vectors,dictionaries

Post by caseih »

FB's built-in data types include dynamic arrays, strings, and numeric types. The data structures you mention are not part of the FB compiler, nor are implementations provided in the runtime library.

However, If you search this forum, you can find object-oriented implementations of other data structures like lists and hashtables (which are dictionaries). Object-oriented programming allows you to create customized data structures that can act almost like built-in types, with normal expression operators overridden to allow the same syntax as built-in types. Assignment, equality, comparisons, etc. Although FB does not support template-based generic programming like other languages, you can still pretty much make any data structure in FB.
zelda64bit
Posts: 27
Joined: Mar 13, 2021 10:18

Re: lists,vectors,dictionaries

Post by zelda64bit »

caseih wrote:FB's built-in data types include dynamic arrays, strings, and numeric types. The data structures you mention are not part of the FB compiler, nor are implementations provided in the runtime library.

However, If you search this forum, you can find object-oriented implementations of other data structures like lists and hashtables (which are dictionaries). Object-oriented programming allows you to create customized data structures that can act almost like built-in types, with normal expression operators overridden to allow the same syntax as built-in types. Assignment, equality, comparisons, etc. Although FB does not support template-based generic programming like other languages, you can still pretty much make any data structure in FB.
And how can I create a list that allows me to save and delete objects? Some examples to learn.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: lists,vectors,dictionaries

Post by fxm »

For example in the documentation:
Linked Lists
zelda64bit
Posts: 27
Joined: Mar 13, 2021 10:18

Re: lists,vectors,dictionaries

Post by zelda64bit »

Thanks for the example.But how is it used? and how to go through that list with a loop?
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: lists,vectors,dictionaries

Post by fxm »

A small use case (for integers) is integrated in the code after the declarations (see from line #18 to line #35):

Code: Select all

Dim As listnode Ptr list, node
Dim As Integer Ptr item
list = ListCreate()
item = ListAdd(list, CAllocate(Len(Integer)))
*item = 4
item = ListAdd(list, CAllocate(Len(Integer)))
*item = 44
item = 0 ' just to show it works
node = ListGetFirst(list)

While node <> 0
    Print "found item"
    item = ListGetData(node)
    Print *item
    node = ListRemove(node,1)
Wend

While Inkey$ = "" : Wend
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

Re: lists,vectors,dictionaries

Post by WQ1980 »

FreeBasic containers (map , vector , list , queue , stack)
viewtopic.php?f=8&t=29320
zelda64bit
Posts: 27
Joined: Mar 13, 2021 10:18

Re: lists,vectors,dictionaries

Post by zelda64bit »

Thank you all for the help.
Lost Zergling
Posts: 538
Joined: Dec 02, 2011 22:51
Location: France

Re: lists,vectors,dictionaries

Post by Lost Zergling »

Also have a look to lzle in projects.
zelda64bit
Posts: 27
Joined: Mar 13, 2021 10:18

Re: lists,vectors,dictionaries

Post by zelda64bit »

Lost Zergling thanks for the suggestion.
Post Reply