Double Hashing

Total Page:16

File Type:pdf, Size:1020Kb

Double Hashing Double Hashing Intro & Coding Hashing Hashing - provides O(1) time on average for insert, search and delete Hash function - maps a big number or string to a small integer that can be used as index in hash table. Collision - Two keys resulting in same index. Hashing – a Simple Example ● Arbitrary Size à Fix Size 0 1 2 3 4 Hashing – a Simple Example ● Arbitrary Size à Fix Size Insert(0) 0 % 5 = 0 0 1 2 3 4 0 Hashing – a Simple Example ● Arbitrary Size à Fix Size Insert(0) 0 % 5 = 0 Insert(5321) 5321 % 5 = 1 0 1 2 3 4 0 5321 Hashing – a Simple Example ● Arbitrary Size à Fix Size Insert(0) 0 % 5 = 0 Insert(5321) 5321 % 5 = 1 Insert(-8002) -8002 % 5 = 3 0 1 2 3 4 0 5321 -8002 Hashing – a Simple Example ● Arbitrary Size à Fix Size Insert(0) 0 % 5 = 0 Insert(5321) 5321 % 5 = 1 Insert(-8002) -8002 % 5 = 3 Insert(20000) 20000 % 5 = 0 0 1 2 3 4 0 5321 -8002 Modular Hashing ● Overall a good simple, general approach to implement a hash map ● Basic formula: ○ h(x) = c(x) mod m ■ Where c(x) converts x into a (possibly) large integer ● Generally want m to be a prime number ○ Consider m = 100 ○ Only the least significant digits matter ■ h(1) = h(401) = h(4372901) Collision Resolution ● A strategy for handling the case when two or more keys to be inserted hash to the same index. ● Closed Addressing § Separate Chaining ● Open Addressing § Linear Probing § Quadratic Probing § Double Hashing Separate Chaining ● Make each cell of hash table point to a linked list of records that have same hash function value Key Hash Value S 2 0 E 0 1 A 0 2 R 4 3 C 4 4 H 4 5 E 0 6 X 2 7 A 0 8 M 4 9 P 3 10 Example from L 3 11 textbook ch3.4 E 0 12 Separate Chaining ● Make each cell of hash table point to a linked list of records that have same hash function value Key Hash Value S 2 0 E 0 1 A 0 2 R 4 3 C 4 4 H 4 5 E 0 6 X 2 7 A 0 8 M 4 9 P 3 10 Example from L 3 11 textbook ch3.4 E 0 12 Open Addressing ● Implementing hashing is to store N key-value pairs in a hash table of size M > N, relying on empty entries in the table to help with collision resolution ● If h(x) == h(y) == i ○ And x is stored at index i in an example hash table ○ If we want to insert y, we must try alternative indices ■ This means y will not be stored at HT[h(y)] ● We must select alternatives in a consistent and predictable way so that they can be located later Linear Probing ● Insert: ○ If we cannot store a key at index i due to collision hi(x) = (Hash(x) + i) % m m = 7 ■ If h0 = (Hash(x) + 0) % m is full we try for h1 Key Hash Value 0 E 12 ■ If h1 = (Hash(x) + 1) % m is full we try for h2 S 5 0 1 C 4 ■ And so on ... E 0 1 ■ Until an open space is found A 5 2 2 ● Search: R 4 3 3 ○ If another key is stored at index i C 4 4 4 R 3 ■ Check i+1, i+2, i+3 … until E 0 6 5 S 0 ● Key is found A 5 8 ● Empty location is found E 0 12 6 A 8 ● We circle through the buffer back to i Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 S 0 A 5 8 E 0 12 6 A 8 Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 5 8 E 0 12 6 A 8 (A, 8) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 5 8 E 0 12 6 Delete the key-value pair (A, 8) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 Re-insert the key-value pair (A, 8) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 (E, 12) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 Delete the key-value pair (E, 12) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 Re-insert the key-value pair (E, 12) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 (C, 4) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 Delete the key-value pair (C, 4) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 C 4 Re-insert the key-value pair (C, 4) Linear Probing ● Delete: Simply setting the key’s table position to null will not work o m = 7 o Need to reinsert into the table all of the keys in the cluster to the deleted key. Key Hash Value 0 E 12 S 5 0 1 C 4 E 0 1 Delete S A 5 2 2 R 4 3 3 C 4 4 4 R 3 E 0 6 5 A 8 A 5 8 E 0 12 6 done Linear Probing ● Delete: o Simply setting the key’s table position to null will not work o Need to reinsert into the table all of the keys in the cluster to the deleted key. Double Hashing ● After a collision, instead of attempting to place the key x in i+1 mod m, look at i+h2(x) mod m ○ h2() is a second, different hash function ■ Should still follow the same general rules as h() to be considered good, but needs to be different from h() ● h(x) == h(y) AND h2(x) == h2(y) should be very unlikely ○ Hence, it should be unlikely for two keys to use the same increment 26 Double Hashing – Example ● Insert Keys: 4, 9, 14, 1, 19 4 mod 5 = 4 9 mod 5 = 4 ● h(x) = x mod 5 14 mod 5 = 4 1 mod 5 = 1 ● h2(x) = 3 – (x mod 3) 19 mod 5 = 4 0 1 2 3 4 Double Hashing – Example ● Insert Keys: 4, 9, 14, 1, 19 4 mod 5 = 4 9 mod 5 = 4 3 - (9 mod 3) = 3 ● h(x) = x mod 5 14 mod 5 = 4 3 - (14 mod 3) = 1 1 mod 5 = 1 ● h2(x) = 3 – (x mod 3) 19 mod 5 = 4 3 - (19 mod 3) = 2 0 1 2 3 4 14 1 9 19 4 Example ● https://www.cs.usfca.edu/~galles/visualization/ClosedHash.ht ml.
Recommended publications
  • Hash Tables & Searching Algorithms
    Search Algorithms and Tables Chapter 11 Tables • A table, or dictionary, is an abstract data type whose data items are stored and retrieved according to a key value. • The items are called records. • Each record can have a number of data fields. • The data is ordered based on one of the fields, named the key field. • The record we are searching for has a key value that is called the target. • The table may be implemented using a variety of data structures: array, tree, heap, etc. Sequential Search public static int search(int[] a, int target) { int i = 0; boolean found = false; while ((i < a.length) && ! found) { if (a[i] == target) found = true; else i++; } if (found) return i; else return –1; } Sequential Search on Tables public static int search(someClass[] a, int target) { int i = 0; boolean found = false; while ((i < a.length) && !found){ if (a[i].getKey() == target) found = true; else i++; } if (found) return i; else return –1; } Sequential Search on N elements • Best Case Number of comparisons: 1 = O(1) • Average Case Number of comparisons: (1 + 2 + ... + N)/N = (N+1)/2 = O(N) • Worst Case Number of comparisons: N = O(N) Binary Search • Can be applied to any random-access data structure where the data elements are sorted. • Additional parameters: first – index of the first element to examine size – number of elements to search starting from the first element above Binary Search • Precondition: If size > 0, then the data structure must have size elements starting with the element denoted as the first element. In addition, these elements are sorted.
    [Show full text]
  • Chapter 5 Hashing
    Introduction hashing performs basic operations, such as insertion, Chapter 5 deletion, and finds in average time Hashing 2 Hashing Hashing Functions a hash table is merely an of some fixed size let be the set of search keys hashing converts into locations in a hash hash functions map into the set of in the table hash table searching on the key becomes something like array lookup ideally, distributes over the slots of the hash table, to minimize collisions hashing is typically a many-to-one map: multiple keys are if we are hashing items, we want the number of items mapped to the same array index hashed to each location to be close to mapping multiple keys to the same position results in a example: Library of Congress Classification System ____________ that must be resolved hash function if we look at the first part of the call numbers two parts to hashing: (e.g., E470, PN1995) a hash function, which transforms keys into array indices collision resolution involves going to the stacks and a collision resolution procedure looking through the books almost all of CS is hashed to QA75 and QA76 (BAD) 3 4 Hashing Functions Hashing Functions suppose we are storing a set of nonnegative integers we can also use the hash function below for floating point given , we can obtain hash values between 0 and 1 with the numbers if we interpret the bits as an ______________ hash function two ways to do this in C, assuming long int and double when is divided by types have the same length fast operation, but we need to be careful when choosing first method uses
    [Show full text]
  • Cuckoo Hashing
    Cuckoo Hashing Rasmus Pagh* BRICSy, Department of Computer Science, Aarhus University Ny Munkegade Bldg. 540, DK{8000 A˚rhus C, Denmark. E-mail: [email protected] and Flemming Friche Rodlerz ON-AIR A/S, Digtervejen 9, 9200 Aalborg SV, Denmark. E-mail: ff[email protected] We present a simple dictionary with worst case constant lookup time, equal- ing the theoretical performance of the classic dynamic perfect hashing scheme of Dietzfelbinger et al. (Dynamic perfect hashing: Upper and lower bounds. SIAM J. Comput., 23(4):738{761, 1994). The space usage is similar to that of binary search trees, i.e., three words per key on average. Besides being conceptually much simpler than previous dynamic dictionaries with worst case constant lookup time, our data structure is interesting in that it does not use perfect hashing, but rather a variant of open addressing where keys can be moved back in their probe sequences. An implementation inspired by our algorithm, but using weaker hash func- tions, is found to be quite practical. It is competitive with the best known dictionaries having an average case (but no nontrivial worst case) guarantee. Key Words: data structures, dictionaries, information retrieval, searching, hash- ing, experiments * Partially supported by the Future and Emerging Technologies programme of the EU under contract number IST-1999-14186 (ALCOM-FT). This work was initiated while visiting Stanford University. y Basic Research in Computer Science (www.brics.dk), funded by the Danish National Research Foundation. z This work was done while at Aarhus University. 1 2 PAGH AND RODLER 1. INTRODUCTION The dictionary data structure is ubiquitous in computer science.
    [Show full text]
  • Hashing (Part 2)
    Hashing (part 2) CSE 2011 Winter 2011 14 March 2011 1 Collision Handling Separate chaining Pbi(Probing (open a ddress ing ) Linear probing Quadratic probing Double hashing 2 1 Quadratic Probing Linear probing: Quadratic probing Insert item (k, e) A[i] is occupied i = h(k) Try A[(i+1) mod N]: used A[i] is occupied Try A[(i+22) mod N]: used Try A[(i+1) mod N]: used Try A[(i+32) mod N] Try A[(i+2) mod N] and so on and so on until an empty cell is found May not be able to find an empty cell if N is not prime, or the hash table is at least half full 3 Double Hashing Double hashing uses a Insert item (k, e) secondary hash function i = h(()k) d(k) and handles collisions A[i] is occupied by placing an item in the first available cell of the Try A[(i+d(k))mod N]: used series Try A[(i+2d(k))mod N]: used (i j d(k)) mod N Try A[(i+3d(k))mod N] for j 0, 1, … , N 1 and so on until The secondary hash an empty cell is found function d(k) cannot have zero values The table size N must be a prime to allow probing of all the cells 4 2 Example of Double Hashing kh(k ) d (k ) Probes Consider a hash 18 5 3 5 tbltable s tor ing itinteger 41 2 1 2 22 9 6 9 keys that handles 44 5 5 5 10 collision with double 59 7 4 7 32 6 3 6 hashing 315 4 590 N 13 73 8 4 8 h(k) k mod 13 d(k) 7 k mod 7 0123456789101112 Insert keys 18, 41, 22, 44, 59, 32, 31, 73, in this order 31 41 18 32 59 73 22 44 0123456789101112 5 Double Hashing (2) d(k) should be chosen to minimize clustering Common choice of compression map for the secondary hash function: d(k) q k mod q where q N q is a prime The possible values for d(k) are 1, 2, … , q Note: linear probing has d(k) 1.
    [Show full text]
  • Linear Probing with Constant Independence
    Linear Probing with Constant Independence Anna Pagh, Rasmus Pagh, and Milan Ruˇzi´c IT University of Copenhagen, Rued Langgaards Vej 7, 2300 København S, Denmark. Abstract. Hashing with linear probing dates back to the 1950s, and is among the most studied algorithms. In recent years it has become one of the most important hash table organizations since it uses the cache of modern computers very well. Unfortunately, previous analysis rely either on complicated and space consuming hash functions, or on the unrealistic assumption of free access to a truly random hash function. Already Carter and Wegman, in their seminal paper on universal hashing, raised the question of extending their analysis to linear probing. However, we show in this paper that linear probing using a pairwise independent family may have expected logarithmic cost per operation. On the positive side, we show that 5-wise independence is enough to ensure constant expected time per operation. This resolves the question of finding a space and time efficient hash function that provably ensures good performance for linear probing. 1 Introduction Hashing with linear probing is perhaps the simplest algorithm for storing and accessing a set of keys that obtains nontrivial performance. Given a hash function h, a key x is inserted in an array by searching for the first vacant array position in the sequence h(x), h(x) + 1, h(x) + 2,... (Here, addition is modulo r, the size of the array.) Retrieval of a key proceeds similarly, until either the key is found, or a vacant position is encountered, in which case the key is not present in the data structure.
    [Show full text]
  • More Analysis of Double Hashing for Balanced Allocations
    More Analysis of Double Hashing for Balanced Allocations Michael Mitzenmacher⋆ Harvard University, School of Engineering and Applied Sciences [email protected] Abstract. With double hashing, for a key x, one generates two hash values f(x) and g(x), and then uses combinations (f(x)+ ig(x)) mod n for i = 0, 1, 2,... to generate multiple hash values in the range [0, n − 1] from the initial two. For balanced allocations, keys are hashed into a hash table where each bucket can hold multiple keys, and each key is placed in the least loaded of d choices. It has been shown previously that asymp- totically the performance of double hashing and fully random hashing is the same in the balanced allocation paradigm using fluid limit methods. Here we extend a coupling argument used by Lueker and Molodowitch to show that double hashing and ideal uniform hashing are asymptotically equivalent in the setting of open address hash tables to the balanced al- location setting, providing further insight into this phenomenon. We also discuss the potential for and bottlenecks limiting the use this approach for other multiple choice hashing schemes. 1 Introduction An interesting result from the hashing literature shows that, for open addressing, double hashing has the same asymptotic performance as uniform hashing. We explain the result in more detail. In open addressing, we have a hash table with n cells into which we insert m keys; we use α = m/n to refer to the load factor. Each element is placed according to a probe sequence, which is a permutation of the cells.
    [Show full text]
  • An Overview of Cuckoo Hashing Charles Chen
    An Overview of Cuckoo Hashing Charles Chen 1 Abstract Cuckoo Hashing is a technique for resolving collisions in hash tables that produces a dic- tionary with constant-time worst-case lookup and deletion operations as well as amortized constant-time insertion operations. First introduced by Pagh in 2001 [3] as an extension of a previous static dictionary data structure, Cuckoo Hashing was the first such hash table with practically small constant factors [4]. Here, we first outline existing hash table collision poli- cies and go on to analyze the Cuckoo Hashing scheme in detail. Next, we give an overview of (c; k)-universal hash families, and finally, we summarize some selected experimental results comparing the varied collision policies. 2 Introduction The dictionary is a fundamental data structure in computer science, allowing users to store key-value pairs and look up by key the corresponding value in the data structure. The hash table provides one of the most common and one of the fastest implementations of the dictionary data structure, allowing for amortized constant-time lookup, insertion and deletion operations.1 In its archetypal form, a hash function h computed on the space of keys is used to map each key to a location in a set of bucket locations fb0; ··· ; br−1g. The key, as well as, potentially, some auxiliary data (termed the value), is stored at the appropriate bucket location upon insertion. Upon deletion, the key with its value is removed from the appropriate bucket, and in lookup, such a key-value pair, if it exists, is retrieved by looking at the bucket location corresponding to the hashed key value.
    [Show full text]
  • Hashing, Load Balancing and Multiple Choice
    Full text available at: http://dx.doi.org/10.1561/0400000070 Hashing, Load Balancing and Multiple Choice Udi Wieder VMware Research [email protected] Boston — Delft Full text available at: http://dx.doi.org/10.1561/0400000070 Foundations and Trends R in Theoretical Computer Science Published, sold and distributed by: now Publishers Inc. PO Box 1024 Hanover, MA 02339 United States Tel. +1-781-985-4510 www.nowpublishers.com [email protected] Outside North America: now Publishers Inc. PO Box 179 2600 AD Delft The Netherlands Tel. +31-6-51115274 The preferred citation for this publication is U. Wieder. Hashing, Load Balancing and Multiple Choice. Foundations and Trends R in Theoretical Computer Science, vol. 12, no. 3-4, pp. 275–379, 2016. R This Foundations and Trends issue was typeset in LATEX using a class file designed by Neal Parikh. Printed on acid-free paper. ISBN: 978-1-68083-282-2 c 2017 U. Wieder All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, mechanical, photocopying, recording or otherwise, without prior written permission of the publishers. Photocopying. In the USA: This journal is registered at the Copyright Clearance Cen- ter, Inc., 222 Rosewood Drive, Danvers, MA 01923. Authorization to photocopy items for internal or personal use, or the internal or personal use of specific clients, is granted by now Publishers Inc for users registered with the Copyright Clearance Center (CCC). The ‘services’ for users can be found on the internet at: www.copyright.com For those organizations that have been granted a photocopy license, a separate system of payment has been arranged.
    [Show full text]
  • Module 5: Hashing
    Module 5: Hashing CS 240 - Data Structures and Data Management Reza Dorrigiv, Daniel Roche School of Computer Science, University of Waterloo Winter 2010 Reza Dorrigiv, Daniel Roche (CS, UW) CS240 - Module 5 Winter 2010 1 / 27 Theorem: In the comparison model (on the keys), Ω(log n) comparisons are required to search a size-n dictionary. Proof: Similar to lower bound for sorting. Any algorithm defines a binary decision tree with comparisons at the nodes and actions at the leaves. There are at least n + 1 different actions (return an item, or \not found"). So there are Ω(n) leaves, and therefore the height is Ω(log n). Lower bound for search The fastest implementations of the dictionary ADT require Θ(log n) time to search a dictionary containing n items. Is this the best possible? Reza Dorrigiv, Daniel Roche (CS, UW) CS240 - Module 5 Winter 2010 2 / 27 Proof: Similar to lower bound for sorting. Any algorithm defines a binary decision tree with comparisons at the nodes and actions at the leaves. There are at least n + 1 different actions (return an item, or \not found"). So there are Ω(n) leaves, and therefore the height is Ω(log n). Lower bound for search The fastest implementations of the dictionary ADT require Θ(log n) time to search a dictionary containing n items. Is this the best possible? Theorem: In the comparison model (on the keys), Ω(log n) comparisons are required to search a size-n dictionary. Reza Dorrigiv, Daniel Roche (CS, UW) CS240 - Module 5 Winter 2010 2 / 27 Lower bound for search The fastest implementations of the dictionary ADT require Θ(log n) time to search a dictionary containing n items.
    [Show full text]
  • Hashing and Hash Tables
    Hash tables Professors Clark F. Olson and Carol Zander Hash tables Binary search trees are data structures that allow us to perform many operations in O(log n) time on average for a collection of n objects (and balanced binary search trees can guarantee this in the worst case). However, if we are only concerned with insert/delete/retrieve operations (not sorting, searching, findMin, or findMax) then we can sometimes do even better. Hash tables are able to perform these operations in O(1) average time under some assumptions. The basic idea is to use a hash function that maps the items we need to store into positions in an array where it can be stored. Since ASCII characters use seven bits, we could hash all three‐letter strings according to the following function: hash(string3) = int(string3[0]) + int(string3[1]) * 128 + int(string3[2]) * 128 * 128 This guarantees that each three‐letter string is hashed to a different number. In the ideal case, you know every object that you could ever need to store in advance and you can devise a “perfect” hash function that maps each object to a different number and use each number from 0 to n‐1, where n is the number of objects that you need to store. There are cases where this can be achieved. One example is hashing keywords in a programming language. You know all of the n keywords in advance and sometimes a function can be determined that maps these perfectly into the n values from 0 to n‐1.
    [Show full text]
  • Handling Collisions
    CMSC 420 Dave Mount CMSC 420: Lecture 11 Hashing - Handling Collisions Hashing: In the previous lecture we introduced the concept of hashing as a method for imple- menting the dictionary abstract data structure, supporting insert(), delete() and find(). Recall that we have a table of given size m, called the table size. We select an easily com- putable hash function h(x), which is designed to scatter the keys in a virtually random manner to indices in the range [0..m-1]. We then store x (and its associated value) in index h(x) in the table. In the previous lecture we discussed how to design a hash function in order to achieve good scattering properties. But, given even the best hash function, it is possible that distinct keys can map to the same location, that is, h(x) = h(y), even though x 6= y. Such events are called collisions, and a fundamental aspect in the design of a good hashing system how collisions are handled. We focus on this aspect of hashing in this lecture, called collision resolution. Separate Chaining: If we have additional memory at our disposal, a simple approach to collision resolution, called separate chaining, is to store the colliding entries in a separate linked list, one for each table entry. More formally, each table entry stores a reference to a list data structure that contains all the dictionary entries that hash to this location. To make this more concrete, let h be the hash function, and let table[] be an m-element array, such that each element table[i] is a linked list containing the key-value pairs (x; v), such that h(x) = i.
    [Show full text]
  • Segmented Hash: an Efficient Hash
    Segmented Hash: An Efficient Hash Table Implementation for High Performance Networking Subsystems Sailesh Kumar Patrick Crowley Washington University Washington University Computer Science and Engineering Computer Science and Engineering St. Louis, MO 63130-4899 St. Louis, MO 63130-4899 +1-314-935-4306 +1-314-935-9186 [email protected] [email protected] ABSTRACT resolution policy and often dramatically increases the cost of the Hash tables provide efficient table implementations, achieving primitive operations. In fact, as the load increases, the average O(1), query, insert and delete operations at low loads. However, at query time increases steadily and very large worst case query moderate or high loads collisions are quite frequent, resulting in times become more likely. decreased performance. In this paper, we propose the segmented In this paper, we propose a hash table architecture, called a hash table architecture, which ensures constant time hash segmented hash table, that improves the performance of any operations at high loads with high probability. To achieve this, the collision resolution policy while minimizing memory bandwidth hash memory is divided into N logical segments so that each requirements. A segmented hash table uses multiple logical hash incoming key has N potential storage locations; the destination tables, or segments, to improve the distribution of keys. On an segment is chosen so as to minimize collisions. In this way, insert operation, for example, each segment contains a potential collisions, and the associated probe sequences, are dramatically location for the key; of these available choices, one is chosen that reduced. In order to keep memory utilization minimized, minimizes collisions.
    [Show full text]