FreeBasic containers (map , vector , list , queue , stack)

User projects written in or related to FreeBASIC.
VANYA
Posts: 1507
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

FreeBasic containers (map , vector , list , queue , stack)

Postby VANYA » Apr 14, 2021 9:30

Hi All!

Implementation of dynamic data types for Freebasic. This implementation is built on the basis of templates (macros), which makes it possible to use it for almost any data type.

In stock:

1) MAP - dictionary (associative array), created on the basis of a balanced tree
2) VECTOR - dynamic array, with the ability to insert and delete any number of cells and much more useful opportunities
3) LIST - doubly linked list
4) QUEUE
5) STACK

Full description, examples and possibilities are described in the help.

License: MIT

Download
kcvinu
Posts: 212
Joined: Oct 07, 2015 16:44
Location: Keralam, India

Re: FreeBasic containers (map , vector , list , queue , stack)

Postby kcvinu » May 07, 2021 23:58

@Vanya,
Thanks for the much needed library.
I just download it and started reading the chm file. When I read about the list, I found this.
list_type - List Type (Data Type to save in List) . Data type can be: any standart type , including pointers, except (any ptr)

Can I use my own UDT ?
VANYA
Posts: 1507
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: FreeBasic containers (map , vector , list , queue , stack)

Postby VANYA » May 08, 2021 3:47

Can I use my own UDT ?


Hi kcvinu!

Code: Select all

#include "LIST.bi"

type Q
   i as Long
   s as Zstring*10
End Type

type PQ as Q ptr ' pseudonym Q ptr

MListTemplate(PQ) ' macro for PQ

Dim p As TLISTPQ ' create list with Q ptr

'fill list
For i As Long = 0 To 10   
   dim qTemp as PQ = new Q ' alloc memory for type Q ptr
   qTemp->i = i
   qTemp->s = "value" & i
   p.Add(qTemp)   
Next
' print values
For i As Long = 0 To 10
   ? (p.GetValueIndex(i))->i , (p.GetValueIndex(i))->s   
Next
' delete nodes from list
For i As Long = 10 To 0 step -1
   delete p.GetValueIndex(i) ' delete memory for type Q ptr
   p.DeleteItemIndex(i) ' delete nodes
Next
? "Size list=" , p.GetSize()
sleep


You can work with a type using vectors (in my opinion, this is more convenient):

Code: Select all

#include "VECTOR.bi"

type Q
   i as Long
   s as Zstring*10
End Type

type pQ as Q ptr

MVectorTemplate(pQ ,  1 )

dim V as TVECTORPQ

for i as Long = 0 to 10
   dim t as Q
   t.i = i
   t.s = "value" & i
   V.push_back(@t)
Next

for i as Long = 0 to V.size()-1
   ? V[i]->i , V[i]->s
Next

V.clear()
Sleep


In addition, vectors have the same data access speed as arrays, that is, faster than in a linked list.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: FreeBasic containers (map , vector , list , queue , stack)

Postby Cretin Ho » May 16, 2021 7:48

What about more data structures? Before your library, I tried to use klib with FreeBASIC but always failed:

https://attractivechaos.github.io/klib/#About

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 6 guests