Dictionary Class

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

Re: Dictionary Class

Postby paul doe » May 16, 2018 18:25

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
Posts: 8536
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

Re: Dictionary Class

Postby fxm » May 16, 2018 19:03

fxm
Posts: 8536
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

Re: Dictionary Class

Postby fxm » May 16, 2018 19:22

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
Posts: 830
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Postby paul doe » May 16, 2018 19:48

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
Posts: 830
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Postby paul doe » May 16, 2018 20:05

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: 103
Joined: Apr 10, 2010 11:41
Location: Japan
Contact:

Re: Dictionary Class

Postby Makoto WATANABE » May 18, 2018 3:16

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
Posts: 830
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Postby paul doe » May 18, 2018 3:52

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: 103
Joined: Apr 10, 2010 11:41
Location: Japan
Contact:

Re: Dictionary Class

Postby Makoto WATANABE » May 18, 2018 13:39

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
Posts: 8536
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

Re: Dictionary Class

Postby fxm » May 18, 2018 14:24

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

Re: Dictionary Class

Postby paul doe » May 18, 2018 14:43

You're welcome.

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

Re: Dictionary Class

Postby Provoni » May 18, 2018 15:50

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
Posts: 830
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Postby paul doe » May 18, 2018 16:15

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: 291
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Dictionary Class

Postby Provoni » May 18, 2018 17:39

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
Posts: 830
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Dictionary Class

Postby paul doe » May 18, 2018 19:45

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: 291
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Dictionary Class

Postby Provoni » May 18, 2018 22:03

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

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests