Dictionary Class

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Post by paul doe »

fxm wrote:I get the same error as Makoto WATANABE.
(my previous remark is still valid in my opinion)
Both of you have the last version? I don't get an error here (downloaded it fresh again)...
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Dictionary Class

Post by fxm »

fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Dictionary Class

Post by fxm »

I have not re-tested it but I now see on the same site that the IDictionary type no longer has Let operator declared in its protected section (or elsewhere).
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Post by paul doe »

Let me double check it. Seems like and old branch of it got mixed.

EDIT: Nope. In light of your last answer, seems like you're using the previous header, like Makoto. Updating the header with the one found in the repo should solve the issue. Also, the offending class is the reference implementation (the Dictionary class proper), which I also updated recently.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Post by paul doe »

fxm wrote:(my previous remark is still valid in my opinion)
Of course. I simply stated why I did things the way I did. Code like this, altough valid, doesn't really make any sense:

Code: Select all

dim as collections.IDictionary myDic = collections.IDictionary()
That is, in FreeBasic you don't really have any control on how classes are inherited, you either inherit them or not.
Makoto WATANABE
Posts: 231
Joined: Apr 10, 2010 11:41
Location: Japan
Contact:

Re: Dictionary Class

Post by Makoto WATANABE »

Dear paul doe;

> What are you trying to accomplish, concretely?

I simpley want to try your examples.

Only the following version is fail with compilation.
fb-dictionary-master20180511\fb-dict-example-1.bas

The following past versions were compiled correctly and worked as expected.

fb-dictionary-master20180503\fb-dict-example.bas
fb-dictionary-master20180505-1\fb-dict-example.bas
fb-dictionary-master20180505-2\fb-dict-example.bas
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Post by paul doe »

Makoto WATANABE wrote: I simpley want to try your examples.

Only the following version is fail with compilation.
fb-dictionary-master20180511\fb-dict-example-1.bas

The following past versions were compiled correctly and worked as expected.
Hi Makoto,

Did you remember to update the header and/or libs? If you copied the code (or the libraries) to your fbc installation, remove them. Then, assuming that you downloaded the code from the repository and extracted it as-is (without changing the folder name, which is by default 'fb-dictionary-master'), copy all the '.lib' files of the 'fb-dictionary-master/inc' folder to the folder where the examples are (in this case, that would be the 'fb-dictionary-master' folder), and then run the examples again. They should work (they do, I checked it again just now).

I'm very sorry for the inconvenience. Soon I'll finish it (I only need minor changes) and be done, so the code can be considered 'closed'. Perhaps the 'release early-release often' mantra of Open Software isn't for me after all =D
Makoto WATANABE
Posts: 231
Joined: Apr 10, 2010 11:41
Location: Japan
Contact:

Re: Dictionary Class

Post by Makoto WATANABE »

Dear paul doe;

Thanks for your quick reply.

Sorry I can not find the '.lib' files in the 'fb-dictionary-master/inc' folder at your repository GitHub.
https://github.com/glasyalabolas/fb-dictionary
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Dictionary Class

Post by fxm »

'.lib' files are '.a' files in FreeBASIC.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Post by paul doe »

You're welcome.

I modified the repo. Just extract the folder and run the examples from there. They should work fine.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Dictionary Class

Post by Provoni »

Hey paul doe,

I am trying to evaluate if your "Dictionary Class" could be useful to any of my projects but am still unsure to what it does.

Does it store things like, name1 = 15, name2 = 20, name3 = 25?

Thank you.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Post by paul doe »

Hi Provoni,

Dictionaries (aka hash tables) map key-value pairs, so yes, it can store anything, using any key you desire (be it a string, a number, anything you want).

Check the examples in the repository to 'get a feel' on how this is done (especially the first and second ones, that map string keys to objects and function pointers, respectively). If you need further explanations on how to code your own dictionary (using this implementation as a base), just ask. Glad you find it useful.
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Dictionary Class

Post by Provoni »

Thank you paul doe,

I am looking for something that can store gigabytes of information, as RAM allows, with fast retrieval. The key will be a number smaller than a 64-bit signed integer and the stored value will be a number smaller than a unsigned byte. The storing will be done only once and then it will function as a lookup table. Given that the size will be a couple of gigabytes, how much retrievals per second would your "Dictionary Class" achieve?

Thanks
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Post by paul doe »

Provoni wrote:I am looking for something that can store gigabytes of information, as RAM allows, with fast retrieval. The key will be a number smaller than a 64-bit signed integer and the stored value will be a number smaller than a unsigned byte. The storing will be done only once and then it will function as a lookup table. Given that the size will be a couple of gigabytes, how much retrievals per second would your "Dictionary Class" achieve?
In that case, this is the ideal data structure to use. Have a look at 'fb-dict-example-6.bas', it should give you an idea. The code runs until it reaches 5,000,000 million entries, but you'll probably run out of memory before that (or out of patience, if you don't comment out the prints). On my machine (a crappy Celeron laptop), it's about ~65000 retrievals per second, but this number is constant and doesn't depend on the size of the data the dictionary holds.

By the way, note that the dictionary stores pointers to data, not data itself. Ergo, you can use it to address the data directly from disk (no need to fit it to memory; only a small descriptor could be used), provided you can implement it (ask if you can't).
Provoni
Posts: 513
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Dictionary Class

Post by Provoni »

paul doe,

The speed seems good. How much memory would your "data structure" use with 500,000,000 entries if each entry is a unique 64-bit integer key holding a ubyte value?
paul doe wrote: By the way, note that the dictionary stores pointers to data, not data itself. Ergo, you can use it to address the data directly from disk (no need to fit it to memory; only a small descriptor could be used), provided you can implement it (ask if you can't).
So it can not be used to store information? Can it store the number 34 to key 208827064571 so that later on key 208827064571 can be used to retrieve the number 34?

Thanks
Post Reply