flat assembler
Message board for the users of flat assembler.
Index
> Main > Search hash in hash-table [algorithm] |
Author |
|
LocoDelAssembly 18 Feb 2013, 22:23
You should use the (hash_value mod array.size) as an index of the array instead of searching, that way you get O(1) access instead of the O(n) you have now.
If you have collisions you'll need to store in the array pointers to lists (or make each array entry hold several entries if that solves the issue). Also google for perfect hashing which is suitable for static arrays. |
|||
18 Feb 2013, 22:23 |
|
hopcode 19 Feb 2013, 06:28
there are lot of ways to implement it. but essentially as Loco suggested.
a simple one http://code.google.com/p/x64lab/source/browse/develop/ide/wspace.asm line 2534 for utf-16 directory. you allocate the table on the stack, etc.etc, accordinng the number of bits you need (choos it carefully!) look at the sdbm hash, good for general purpose. here some macros i wrote (my improvement on it tested exstensively works without doubt better on labels L_00000, directory, and english dictionary) http://code.google.com/p/x64lab/source/browse/develop/macro/mrk_macrow.inc line 519,550 Cheers, _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
19 Feb 2013, 06:28 |
|
JohnFound 19 Feb 2013, 07:05
If you can't build hash tables, because of some reason, you can try to keep the array sorted and use binary search. It will speed the things up.
|
|||
19 Feb 2013, 07:05 |
|
f0dder 19 Feb 2013, 23:30
1) you're linearly scanning a table of hash values - you don't have a hash-table. O(n) lookup speed is bad.
2) checking for table end with byte(0) instead of dword(0) seems potentially dangerous. 3) as already mentioned, if your hash-table is static, you really should google perfect hashing - if it's suitable for your scenario, you get true O(1) lookups. 4) if for some reason you can't/won't do a true hash-table, at least sort the input values and use a binary search, that gives you O(log n) lookup speed (i.e. searching the entire DWORD space would require a worst-case of 32 iterations to find your item). |
|||
19 Feb 2013, 23:30 |
|
idle 20 Feb 2013, 12:39
|
|||
20 Feb 2013, 12:39 |
|
hopcode 20 Feb 2013, 13:48
ths is becoming a very useful thread, i think it's time to post this instructional
links if i dint it yet, http://home.comcast.net/~bretm/hash/ Cheers, _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
20 Feb 2013, 13:48 |
|
AsmGuru62 20 Feb 2013, 16:37
I needed that for education!
I know "by guts" what is a hash, but this article going into much needed details. Thanks. |
|||
20 Feb 2013, 16:37 |
|
r22 21 Feb 2013, 18:05
http://reflector.webtropy.com/default.aspx/Net/Net/3@5@50727@3053/DEVDIV/depot/DevDiv/releases/whidbey/netfxsp/ndp/clr/src/BCL/System/Collections/Hashtable@cs/1/Hashtable@cs
The C#.NET HashTable source code is fairly educational. The Insert and ContainsKey methods especially. |
|||
21 Feb 2013, 18:05 |
|
hopcode 23 Feb 2013, 08:17
reading above about the load factor, i would like to point out now that
collisions rate should be solved keeping this points as reference: a) the hash function b) the scheme c) the context a) the hash function generate values from inputs. those values may collide. here a graph, not much readable imho, about how the function works: http://www.fantasy-coders.de/projects/gh/html/x435.html b) the scheme is about the way you manage the table in memory, because you have got some collisions coming from a good/bad a) also deallocation/reallocation in order to increase/decrease/sort free slots (buckets). this scheme for example, http://en.wikipedia.org/wiki/Cuckoo_hashing or linear probing the focus here is on the birthday's paradox http://en.wikipedia.org/wiki/Birthday_problem c) the context is the last but not least. because one thing is hashing an english dictionary, one other thing is hashing programmer's labels and symbols, where you may have symbols like j,m,n,o,j1,j2 etc. i cannot find the link of a valuable explanation about python using a clever and elegant scheme on numbers and variables. but here an implementation of the function: http://stackoverflow.com/questions/793761/built-in-python-hash-function Cheers, _________________ ⠓⠕⠏⠉⠕⠙⠑ |
|||
23 Feb 2013, 08:17 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.