Constructing a Hash Table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Constructing a Hash Table

Post by legend986 »

I have two columns in my table. Both of them contains strings whose maximum length can be 16 characters. The number of records are close to a million. I need to make some comparisons between the two columns. To do this, I'm thinking of constructing a Hash Table. How would I do it? Never worked with hashes before, so can someone please guide me?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What kind of comparisons? If they're basic, like matching, there's no need for hashing.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Internals and Portability

Written in C and C++.
Uses GNU Automake (1.4), Autoconf (Version 2.52 or newer), and Libtool for portability.
Works on many different platforms; APIs for C, C++, Eiffel, Java, Perl, PHP, Python, Ruby, and Tcl.
Fully multi-threaded using kernel threads, this means it can easily use multiple CPUs if available.
Very fast B-tree disk tables with index compression and thread-based memory allocation system.
Very fast joins using an optimised one-sweep multi-join, can mix tables from different databases in the same query.
In-memory hash tables which are used as temporary tables.
SQL functions are implemented through a highly optimised class library and should be as fast as possible!
Usually there isn't any memory allocation at all after query initialisation.
There are 10 types of people in this world, those who understand binary and those who don't
ev0l
Forum Commoner
Posts: 56
Joined: Thu Jun 21, 2007 1:50 pm

Re: Constructing a Hash Table

Post by ev0l »

legend986 wrote:I have two columns in my table. Both of them contains strings whose maximum length can be 16 characters. The number of records are close to a million. I need to make some comparisons between the two columns. To do this, I'm thinking of constructing a Hash Table. How would I do it? Never worked with hashes before, so can someone please guide me?
I don't see why you think you need a hash table. You are using a database let the database do the indexing for you.

Hash tables are great at in-memory retrieval. PHP arrays are implemented as hash tables (basically) so in fact you have worked with hashes. If you are interested in learning more on hash tables the [http://en.wikipedia.org/wiki/Hash_tables]article[/url] on Wikipedia is pretty good.

If your data is small enough to fit in memory you might benefit from a MySQL heap table (assuming you are using MySQL) but I would suggest against it in most cases.

Please submit more details on the problem you are having and maybe we could be of more help.
Post Reply