2 * This software is part of the SBCL system. See the README file for
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
15 struct hopscotch_table
{
22 int mem_size
; // in bytes, for zero-filling when done using
24 struct { int n_seeks
, n_probes
; } hit
, miss
;
25 int prev_size
; // in cells, as specified to hopscotch_create()
26 char resized
; // set to 1 if sized up since last reset
27 char rehashing
; // set to 1 during rehash
30 void hopscotch_init();
31 void hopscotch_create(struct hopscotch_table
*,boolean
,int,char);
32 int hopscotch_put(struct hopscotch_table
*,uword_t
,unsigned);
33 int hopscotch_get(struct hopscotch_table
*,uword_t
);
34 int hopscotch_containsp(struct hopscotch_table
*,uword_t
);
35 void hopscotch_reset(struct hopscotch_table
*);
36 void hopscotch_log_stats(struct hopscotch_table
*);
38 /* This confuses me every time I look at it, so here's an example-
39 * Suppose (unrealistically) that a table has a hop range of 4,
40 * and 16 logical bins. The largest logical bin index (= the table mask)
41 * is 15, and there are 3 (not 4) more cells at the end.
42 * So the largest physical index in which you can probe without
43 * overrunning the key array is (mask + range - 1).
44 * i.e. the neighborhood of logical cell index 15 is {15,16,17,18}.
45 * The total count of physical key cells is (mask + 1) + (range - 1)
46 * where (mask + 1) is the logical bin count.
48 #define hopscotch_max_key_index(table) ((table).mask+(table).hop_range-1)
50 #define for_each_hopscotch_cell(loopvar, tablevar) \
51 for(loopvar=hopscotch_max_key_index(tablevar) ; loopvar >= 0 ; --loopvar)