[Gambas-user] Data Structures like C++
Benoît Minisini
gambas at ...1...
Mon May 21 22:25:22 CEST 2012
Le 21/05/2012 21:51, Demosthenes Koptsis a écrit :
> Basic languages have simple data structures like vars and arrays but
> other languages
> like c++ with the help of pointers can have advanced data structures
> like containers etc...
>
> see a full list here
> http://en.wikipedia.org/wiki/List_of_data_structures
>
> i wonder if such data structures can be implemented with gambas with
> pointers and if such an action have any mean for real life
> applications?
>
> Is it possible to have such data structures in gambas?
> How about some of these to be part of the core libraries?
Some data structures are missing, but not so many as you may think at
first sight.
If they are implemented, I don't think they will go inside the
interpreter, to keep its size small (it is already too big for my
tastes), but in an extern component.
* Map/Associative array/Dictionary
* Hash
Use a Collection in both case. If the key is not a string, you must find
a way to identify your key with a unique string.
* Multimap
Use a Collection whose values are arrays.
* List
Use an array. Since CPU have now one, two, three... memory caches,
arrays as almost always faster than linked lists.
* Set
One could use a Collection to emulate it: by transforming a value into a
string key, we can assume that the value belongs to the set if the
collection has something associated with the key.
But it would be better to add a Set native class with a native
implementation (in C. Stop with C++!).
* Multiset
Same remarks (the value is associated to its number of occurence in the
collection).
* Priority queue
Is it worth having a native implementation for that? I don't think so. A
implementation in Gambas should be enough.
* Queue
* Deque
* Stack
Use an Array. The Push() and Pop() methods can help.
* String
We have strings of characters. Is something else really needed?
* Tree
* Graph
Native implementation of that would be interesting.
Any volunteer? :-)
--
Benoît Minisini
More information about the User
mailing list