Engineering a Sorted List Data Structure for 32 Bit Keys∗

Engineering a Sorted List Data Structure for 32 Bit Keys∗

Engineering a Sorted List Data Structure for 32 Bit Keys∗ Roman Dementievy Lutz Kettnery Jens Mehnerty Peter Sandersy Abstract linked sorted list to support fast successor and prede- Search tree data structures like van Emde Boas (vEB) cessor queries. trees are a theoretically attractive alternative to com- However, we are only aware of a single implementa- parison based search trees because they have better tion study [15] where the conclusion is that vEB-trees asymptotic performance for small integer keys and large are of mainly theoretical interest. In fact, our experi- inputs. This paper studies their practicability using 32 ments show that they are slower than comparison based bit keys as an example. While direct implementations of implementations even for 32 bit keys. vEB-trees cannot compete with good implementations In this paper we address the question whether im- of comparison based data structures, our tuned data plementations that exploit integer keys can be a prac- structure significantly outperforms comparison based tical alternative to comparison based implementations. implementations for searching and shows at least com- In Section 2, we develop a highly tuned data structure parable performance for insertion and deletion. for large sorted lists with 32 bit keys. The starting point were vEB search trees as described in [10] but we arrive 1 Introduction at a nonrecursive data structure: We get a three level search tree. The root is represented by an array of size Sorted lists with an auxiliary data structure that sup- 216 and the lower levels use hash tables of size up to ports fast searching, insertion, and deletion are one of 256. Due to this small size, hash functions can be im- the most versatile data structures. In current algorithm plemented by table lookup. Locating entries in these libraries [11, 2], they are implemented using compar- tables is achieved using hierarchies of bit patterns sim- ison based data structures such as ab-trees, red-black ilar to the integer priority queue described in [1]. trees, splay trees, or skip lists (e.g. [11]). These im- Experiments described in Section 3 indicate that plementations support insertion, deletion, and search in this data structure is significantly faster in searching el- time O(log n) and range queries in time O(k + log n) ements than comparison based implementations. For where n is the number of elements and k is the size of insertion and deletion the two alternatives have compa- the output. For w bit integer keys, a theoretically at- rable speed. Section 4 discusses additional issues. tractive alternative are van Emde Boas stratified trees (vEB-trees) that replace the log n by a log w [14, 10]: More Related Work: There are studies on exploiting A vEB tree T for storing subsets M of w = 2k+1 bit integer keys in more restricted data structures. In integers stores the set directly if jMj = 1. Otherwise particular, sorting has been studied extensively (refer it contains a root (hash) table r such that r[i] points k to [13, 7] for a recent overview). Other variants are to a vEB tree Ti for 2 bit integers. Ti represents k 2 k 1 priority queues (e.g. [1]), or data structures supporting the set Mi = fx mod 2 : x 2 M ^ x 2 = ig. fast search in static data [6]. Dictionaries can be top data Furthermore, T stores min M, max M, and a implemented very efficiently using hash tables. structure t consisting of a 2k bit vEB tree storing the k However, none of these data structures is applicable set Mt = x 2 : x 2 M . This data structure takes if we have to maintain a sorted list dynamically. Simple space O(jMj log w) and can be modified to consume only examples are sweep-line algorithms [3] for orthogonal linear space. It can also be combined with a doubly objects,2 best first heuristics (e.g., [8]), or finding free slots in a list of occupied intervals (e.g. [4]). ∗Partially supported by the Future and Emerging Technologies programme of the EU under contract number IST-1999-14186 2 (ALCOM-FT). General line segments are a nice example where a comparison yMPI Informatik, Stuhlsatzenhausweg 85, 66123 Saarbruc¨ ken, based data structure is needed (at least for the Bentley-Ottmann Germany, [dementiev,kettner,jmehnert,sanders]@mpi-sb. algorithm) | the actual coordinates of the search tree entries mpg.de change as the sweep line progresses but the relative order changes 1 i We use the C-like shift operator `', i.e., x i = ¨x=2 ˝. only slowly. 2 The Data Structure Minima and Maxima: For the root and each L2- We now describe a data structure Stree that stores an table and L3-table, we store the smallest and largest ordered set of elements M with 32-bit integer keys sup- element of the corresponding subset of M. We store porting the main operations element insertion, element both the key of the element and a pointer to the element deletion, and locate(y). Locate returns min(x 2 M : list. y ≤ x). The root-top data structure t consists of three bit- We use the following notation: For an integer x, x[i] arrays t1[0::216 − 1], t2[0::4095], and t3[0::63]. We 31 i 1 2 represents the i-th bit, i.e., x = Pi=0 2 x[i]. x[i::j], i ≤ have t [i] = 1 iff Mi 6= ;. t [j] is the logical- j +1, denotes bits i through j in a binary representation or of t1[32j]::t1[32j + 31], i.e., t2[j] = 1 iff 9i 2 j k−i 3 of x = x[0::31], i.e., x[i::j] = Pk=i 2 x[i]. Note that f32j::32j + 31g : Mi 6= ;. Similarly, t [k] is the x[i::i − 1] = 0 represents the empty bit string. The logical-or of t2[32k]::t2[32k + 31] so that t3[k] = 1 iff function msbPos(z) returns the position of the most 9i 2 f1024k::1024k + 1023g : Mi 6= ;. significant nonzero bit in z, i.e., msbPos(z) = blog2 zc = 3 The L2-top data structures ti consists of two bit max fi : x[i] 6= 0g. 1 2 arrays ti [0::255] and ti [0::7] similar to the bit arrays Our Stree stores elements in a doubly linked sorted 1 element list and additionally builds a stratified tree data of the root-top data structure. The 256 bit table ti contains a 1-bit for each nonempty entry of ri and the structure that serves as an index for fast access to the 2 1 elements of the list. If locate actually returns a pointer eight bits in ti contain the logical-or of 32 bits in ti . to the element list, additional operations like successor, This data structure is only allocated if jMij ≥ 2. predecessor, or range queries can also be efficiently The L3-top data structures tij with bit arrays 1 2 implemented. The index data structure consists of tij [0::255] and tij [0::7] reflect the entries of Mij in a the following ingredients arranged in three levels, root, fashion analogous to the L2-top data structure. Level 2 (L2), and Level 3 (L3): Hash Tables use open addressing with linear probing The root-table r contains a plain array with one entry [9, Section 6.4]. The table size is always a power of two for each possible value of the 16 most significant bits between 4 and 256. The size is doubled when a table of the keys. r[i] = null if there is no x 2 M with of size k contains more than 3k=4 entries and k < 256. x[16::31] = i. If jMij = 1, it contains a pointer to the The table shrinks when it contains less than k=4 entries. element list item corresponding to the unique element Since all keys are between 0 and 255, we can afford to of Mi. Otherwise, r[i] points to an L2-table containing implement the hash function as a full lookup table h Mi = fx 2 M : x[16::31] = ig. The two latter cases that is shared between all tables. This lookup table is can be distinguished using a flag stored in the least initialized to a random permutation h : 0::255 ! 0::255. significant bit of the pointer.4 Hash function values for a table of size 256=2i are obtained by shifting h[x] i bits to the right. Note An L2-table ri stores the elements in Mi. If jMij ≥ 2 it uses a hash table storing an entry with key j if that for tables of size 256 we obtain a perfect hash function, i.e., there are no collisions between different 9x 2 Mi : x[8::15] = j. table entries. Let Mij = fx 2 M : x[8::15] = j; x[16::31] = ig. If Figure 1 gives an example summarizing the data jMij j = 1 the hash table entry points to the element list structure. and if jMij j ≥ 2 it points to an L3-table representing Mij using a similar trick as in the root-table. 2.1 Operations: With the data structure in place, An L3-table rij stores the elements in Mij . If the operations are simple in principle although some jMij j ≥ 2, it uses a hash table storing an entry with case distinctions are needed. To give an example, key k if 9x 2 Mij : x[0::7] = k. This entry points Figure 2 contains high level pseudo code for locate(y) to an item in the element list storing the element with that finds the smallest x 2 M with y ≤ x.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us