Re: Ordered list of strings in registry
Jean Truc <[email protected]> Fri, 22 Nov 2024 12:13:21 +0100
| Newsgroups | gmane.comp.lib.fox-toolkit.user |
|---|---|
| Message-ID | <[email protected]> |
OK, I used your tip and it worked well. Thanks! Le 21/11/2024 à 16:06, [email protected] a écrit : > On 2024-11-21 05:55, Jean Truc wrote: >> Hi, >> >> I'm looking for the best way to read and save an ordered list of >> strings from and to the registry. >> >> Something like: >> >> [MY_LIST] >> >> key1=data1 >> >> key2=data2 >> >> key3=data3 >> >> ... >> >> and reading writing the key/data entries in the order they appear in >> the registry file. >> >> I've tried using an FXStringDict dictionary but it's not ordered. It >> seems that the keys are read in a random order. >> >> Any ideas? > > FXRegistry (FXSettings) is a two-level hash table, i.e. a hash-table of > FXStringDict, or string hash-tables. By definition, its not sorted. > > The order is a function of the distribution of the hash-keys of the > strings. We're using the "FNV1a" hash algorithm to compute the > keys, but older FOX versions used a different algorithm. For > access speed the exact hash algorithm doesn't matter, but fewer > collisions is preferable as it maximizes the chance of items with > the same key representing the same strings. > > You can walk the hash tables, skipping over the empty slots, then > place the keys in an array, and sort it. > > // Array with room for N keys... > const FXchar** array=... > > for(i=j=0; i<stringdict.no(); ++i){ > if(stringdict.empty(i)) continue; > array[j++]=stringdict.key(i).text(); > } > > // Sort N keys > qsort(array,N,sizeof(const FXchar*),strcmp); > > Then, mutatis mutandum, you'll have a sorted array. > of the keys. Note the key strings themselves are > not copied, only the pointers are.. > > Hope this helps, > > -- JVZ > > > _______________________________________________ Foxgui-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/foxgui-users