GDBM firstkey and nextkey can't fetch records in the same order as were inserted
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
GDBM firstkey and nextkey can't fetch records in the same order as were inserted
Is it a feature of GDBM that gdbm_firstkey() and gdbm_nextkey() fetches records not in proper order? Is it possible to extract the records in the order as we insert them? It gets the record this way; (Dev-C++ with mingw on win 2003)DB created. DB opened. [I][B]Here is the output:
Quote:
Storing 1 One
Storing 2 Two
Storing 3 Three
Storing 4 Four
done.
3 Three
2 Two
1 One
4 Four
dbf = gdbm_open("arraydb", 512, GDBM_NEWDB,0666, NULL);
if(dbf == NULL){
printf("ERROR: Could not open the DB file.\n");
exit(1);
} else {
printf("DB created.\n");
printf("DB opened.\n");
}
Thank you for your tip but it would be better if you've referred to the exact position of the gnu gdbm manual where it's been mentioned. I think the following is the point you want me to understand; From gdbm manual:
Quote:
9. Sequential access to records.
Quote:
The next two functions allow for accessing all items in the database. This access is not key sequential, but it is guaranteed to visit every key in the database once. The order has to do with the hash values. gdbm_firstkey starts the visit of all keys in the database. gdbm_nextkey finds and reads the next entry in the hash structure for dbf.
Yes, and my apology for not quoting it directly, it sort of jumped out at me and I had a bad moment between not wanting to presume you'd read it nor appear condescending! (shoots foot)
Yes, and my apology for not quoting it directly, it sort of jumped out at me and I had a bad moment between not wanting to presume you'd read it nor appear condescending! (shoots foot)
Please don't make me embarrass. You've done a great job 'case I have had to find myself and the effort I made will help me, (as the old adage says; we remember a for longer period what I learn in harder way or something or something or...).
Thanks again.
Never used gdbm yet, but this sounds wrong: there is no way the process the records sequentially -- in the sequence of the keys, I mean?
Yes, I thought firstkey() pointed to the record that had been
inserted at first so, in that case record number one would have come first. But I didn't realized that gdbm database is a hash table(I assume it is and I don't know how hashing algo works).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.