CollLib 2.0 released

BlitzPlus Forums/BlitzPlus Programming/CollLib 2.0 released

Mahan(Posted 2009) [#1]
CollLib 2.0 runs on both BlitzPlus and Blitz3D and provides Lists, StringLists and StringHashList (a full HashMap).

This really expands the Blitz languages to a new level when it comes to management of massive amounts of Type-instances etc.

(Freeware for any use)

Release thread
http://blitzmax.com/Community/posts.php?topic=86730


Sauer(Posted 2009) [#2]
Is this lists like in Python?

Can you give an example of what this would do?


Mahan(Posted 2009) [#3]
What do you want an example of? This lib mainly provides 3 things: Lists, StringLists, and StringHashLists.

A copy&paste from the README.txt:
       
__What's a List__?

Basically its a list of numbers.
Since all entities and objects in Blitz3D and BlitzPlus are numeric handles
this comes very handy though.

List is very fast both for indexed access aswell as modifications.

Check out the ListDemo.bb for an example.



__What's a StringList__?

This is a ordered list of strings.
Normally strings are in the order you added them, but there are functions
that that lets you insert/delete/swap positions inside the list.
Each string in the stringlist can also optionally have a corresponding
integer value, that can be used for Blitz3D or BlitzPlus handles.

You can also load/save text-files to/from a StringList with a single
command.

StringList is very fast both for indexed access aswell as modifications.

Check out the StringListDemo.bb for an example.



__What's a StringHashList__?

This is a lookup hashtable list/map. (if you got confused read on!)

Easily explained the StringHashList works like an ultra-fast dictionary
or phonebook. You give it a word or a name, and in (almost) no time
at all the StringHashMap returns to you the correct number.

From the example:
The name you look for is called the key. This is a string.
The number the dictionary returns is called the value. This is an integer.

The StringHashMap trades insertion-speed for very high lookup speed.

Check out the StringHashListDemo.bb for an example.



If you want to know more or have a specific question about functionality, just ask and I'll try to show a demo or something :-)


Mahan(Posted 2009) [#4]
I wrote an additional B+ demo here to demonstrate the use of separate lists:

(No nice cleanup, can add that upon request)




Sauer(Posted 2009) [#5]
Ah ok I understand better. So you can pop, push, insert, and remove entries?

Downloading now...

You are quickly becoming the MVP of BlitzPlus.


Mahan(Posted 2009) [#6]

Ah ok I understand better. So you can pop, push, insert, and remove entries?



To create a list use: mylist% = CreateList()
To remove a list use: FreeList(mylist)

With a list you typically just use ListAdd(list%, value%) to add values and then you use ListCount%(list) to check how many values you got and ListGet(list%, index%) to get any value at any time. (Note that index% is zero indexed)


If you want to push and pop like a stack you can do this:

LIFO (last in first out) : 
1) PUSH: 
  ListAdd(listHandle%, <value>)
2) POP: 
  <value>=ListGet(listHandle%, ListCount(listHandle%)-1)
  ListDelete(listHandle%, ListCount(listHandle%)-1)

FIFO (First in first out):
1) PUSH:
  ListAdd(listHandle%, <value>)
2) POP: 
  <value>=ListGet(listHandle%, 0)
  ListDelete(listHandle%, 0)



edit: added some info


Mahan(Posted 2009) [#7]
@Sauer: If you downloaded this lib, be sure to download the new update, and use the new CollLib.decls and CollLib.dll.

I found and fixed a bug today in the StringHashList.


em22(Posted 2009) [#8]
Very nice, this will be very useful for when I'm going to try and do a fuzzy search!


Sauer(Posted 2009) [#9]
I'm currently using the map functionality of this lib in my current project. I was using a single image for the items in my game, but decided to switch to having different items for different images. Rather than edit my item structure to hold this information (which would have required me to edit every aspect of item management) I plan to use a map with the item name as a key and the image handle as the value.

Just thought you'd like to know what your lib is being used for :)


Mahan(Posted 2009) [#10]
Sounds like a good usage example. I'm happy if it simplifies programming in any way. :-)

I was doing something similar in a game I'm writing: This game features a tilemap and the tilemap has Tiles that are mapped to "BaseTiles". Basetiles are the ones holding the unique tile-images. i.e. several Tiles on the tilemap can map the same Basetile if their appearance is identical. I use the name of the images of the Basetiles in a map, to map the tiles to their correct basetiles, in the config files for the game.

(The reason for the Basetile-abstraction (instead of just an image-handle) is that basetiles can be configured with additional properties such as "walkable", "water" etc. so they need to carry with them more than just the tile-image)