Sponsored Content
Full Discussion: Hash Function Speed
Top Forums Programming Hash Function Speed Post 302364229 by jim mcnamara on Thursday 22nd of October 2009 10:40:06 AM
Old 10-22-2009
Your hash function is, um, unusual. Your for loop does nothing. Assuming that is what you really wanted, this is what you function is actually doing:
Code:
int HashTable::hashFunc(const string &key) const
{
  int tableSize = theLists.size();
  int hashVal = 0;
      			
  hashVal = 37*hashVal+key[key.length()];
  return hashVal % tableSize;
}

which is consierably faster - not iterating i over the length of a string.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk Hash Function.

I have a file with a format of A,2 B,2 G,3 A,2 A,3 A,2 D,7 A,2 E,2 A,2 I need to create a sum of each alphabet with the numbers assigned to it using awk. (2 Replies)
Discussion started by: dinjo_jo
2 Replies

2. Shell Programming and Scripting

Print Entire hash list (hash of hashes)

I have a script with dynamic hash of hashes , and I want to print the entire hash (with all other hashes). Itried to do it recursively by checking if the current key is a hash and if yes call the current function again with refference to the sub hash. Most of the printing seems to be OK but in... (1 Reply)
Discussion started by: Alalush
1 Replies

3. Filesystems, Disks and Memory

data from blktrace: read speed V.S. write speed

I analysed disk performance with blktrace and get some data: read: 8,3 4 2141 2.882115217 3342 Q R 195732187 + 32 8,3 4 2142 2.882116411 3342 G R 195732187 + 32 8,3 4 2144 2.882117647 3342 I R 195732187 + 32 8,3 4 2145 ... (1 Reply)
Discussion started by: W.C.C
1 Replies

4. Shell Programming and Scripting

Assigning a hash to another hash key

Hello, I have a hash in hsh. I need to assign it to another hash globalHsh. I think the below statement does not work $globalHsh{$id} = %hsh; What is the right way to assign it? Thanks (3 Replies)
Discussion started by: rsanjay
3 Replies

5. Shell Programming and Scripting

Perl Hash:Can not keep hash data in the same order that it was inserted

Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below. #!/usr/bin/perl use warnings; use Tie::IxHash; use strict; tie (my %programs, "Tie::IxHash"); while (my $line = <DATA>) { chomp $line; my(... (1 Reply)
Discussion started by: jgfcoimbra
1 Replies

6. Shell Programming and Scripting

perl hash - using a range as a hash key.

Hi, In Perl, is it possible to use a range of numbers with '..' as a key in a hash? Something in like: %hash = ( '768..1536' => '1G', '1537..2560' => '2G' ); That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies

7. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

8. Shell Programming and Scripting

Dynamically parse BibTeX and create hash of hash

Hello gurus, Iam trying to parse following BibTex file (bibliography.bib): @book{Lee2000a, abstract = {Abstract goes here}, author = {Lee, Wenke and Stolfo, Salvatore J}, title = {{Data mining approaches for intrusion detection}}, year = {2000} } @article{Forrest1996, abstract =... (0 Replies)
Discussion started by: wakatana
0 Replies

9. Shell Programming and Scripting

Need to print hash of hash in table format

Hi, I have a hash of hash where it has name, activities and count i have data like this - $result->{$name}->{$activities} = $value; content of that are - name - robert tom cat peter activities - running, eating, sleeping , drinking, work i need to print output as below ... (3 Replies)
Discussion started by: asak
3 Replies
QUICKHASHINTSTRINGHASH(3)						 1						 QUICKHASHINTSTRINGHASH(3)

The QuickHashIntStringHash class

INTRODUCTION
This class wraps around a hash containing integer numbers, where the values are strings. Hashes are also available as implementation of the ArrayAccess interface. Hashes can also be iterated over with foreach as the Iterator interface is implemented as well. The order of which elements are returned in is not guaranteed. CLASS SYNOPSIS
QuickHashIntStringHash QuickHashIntStringHash Constants o const integer$QuickHashIntStringHash::CHECK_FOR_DUPES1 o const integer$QuickHashIntStringHash::DO_NOT_USE_ZEND_ALLOC2 o const integer$QuickHashIntStringHash::HASHER_NO_HASH256 o const integer$QuickHashIntStringHash::HASHER_JENKINS1512 o const integer$QuickHashIntStringHash::HASHER_JENKINS21024 Methods o public bool QuickHashIntStringHash::add (int $key, string $value) o public QuickHashIntStringHash::__construct (int $size, [int $options]) o public bool QuickHashIntStringHash::delete (int $key) o public bool QuickHashIntStringHash::exists (int $key) o public mixed QuickHashIntStringHash::get (int $key) o public int QuickHashIntStringHash::getSize (void ) o publicstatic QuickHashIntStringHash QuickHashIntStringHash::loadFromFile (string $filename, [int $size], [int $options]) o publicstatic QuickHashIntStringHash QuickHashIntStringHash::loadFromString (string $contents, [int $size], [int $options]) o public void QuickHashIntStringHash::saveToFile (string $filename) o public string QuickHashIntStringHash::saveToString (void ) o public int QuickHashIntStringHash::set (int $key, string $value) o public bool QuickHashIntStringHash::update (int $key, string $value) PREDEFINED CONSTANTS
o QuickHashIntStringHash::CHECK_FOR_DUPES -If enabled, adding duplicate elements to a set (through either add() or loadFromFile()) will result in those elements to be dropped from the set. This will take up extra time, so only used when it is required. o QuickHashIntStringHash::DO_NOT_USE_ZEND_ALLOC -Disables the use of PHP's internal memory manager for internal set structures. With this option enabled, internal allocations will not count towards the memory_limit settings. o QuickHashIntStringHash::HASHER_NO_HASH -Selects to not use a hashing function, but merely use a modulo to find the bucket list index. This is not faster than normal hashing, and gives more collisions. o QuickHashIntStringHash::HASHER_JENKINS1 -This is the default hashing function to turn the integer hashes into bucket list indexes. o QuickHashIntStringHash::HASHER_JENKINS2 -Selects a variant hashing algorithm. PHP Documentation Group QUICKHASHINTSTRINGHASH(3)
All times are GMT -4. The time now is 05:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy