kh_hash

Members

Aliases

kh_int_hash_func2
alias kh_int_hash_func2 = __ac_Wang_hash
Undocumented in source.

Functions

__ac_Wang_hash
auto __ac_Wang_hash(T key)
Undocumented in source. Be warned that the author may not have intended to support it.
__ac_X31_hash_string
khint_t __ac_X31_hash_string(const(char)* s)
Undocumented in source. Be warned that the author may not have intended to support it.
kh_hash_equal
bool kh_hash_equal(T a, T b)
Undocumented in source. Be warned that the author may not have intended to support it.
kh_hash_equal
bool kh_hash_equal(T* a, T* b)
Undocumented in source. Be warned that the author may not have intended to support it.
kh_hash_equal
bool kh_hash_equal(T a, T b)
Undocumented in source. Be warned that the author may not have intended to support it.
kh_hash_func
auto kh_hash_func(T key)
Undocumented in source. Be warned that the author may not have intended to support it.
kh_hash_func
auto kh_hash_func(T key)
Undocumented in source. Be warned that the author may not have intended to support it.
kh_hash_func
auto kh_hash_func(T* key)
Undocumented in source. Be warned that the author may not have intended to support it.
kh_hash_func
auto kh_hash_func(T key)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

foreach: TODO

/*! @function @abstract Iterate over the entries in the hash table @param h Pointer to the hash table [khash_t(name)*] @param kvar Variable to which key will be assigned @param vvar Variable to which value will be assigned @param code Block of code to execute */ auto kh_foreach(kh_t* h, kvar, vvar, code) { khint_t __i; for (__i = kh_begin(h); __i != kh_end(h); ++__i) { if (!kh_exist(h, __i)) continue; kvar = kh_key(h, __i); vvar = kh_val(h, __i); code; } }

/*! @function @abstract Iterate over the values in the hash table @param h Pointer to the hash table [khash_t(name)*] @param vvar Variable to which value will be assigned @param code Block of code to execute */ auto kh_foreach_value(kh_t* h, vvar, code) { khint_t __i; for (__i = kh_begin(h); __i != kh_end(h); ++__i) { if (!kh_exist(h, __i)) continue; vvar = kh_val(h, __i); code; } }

1     import std.stdio : writeln, writefln;
2 
3     writeln("khash unit tests");
4 
5     // test: numeric key type must be unsigned
6     assert(__traits(compiles, khash!(int, int)) is false);
7     assert(__traits(compiles, khash!(uint,int)) is true);
8 
9 //    auto kh = khash!(uint, char).kh_init();
10 
11     //int absent;
12     //auto k = khash!(uint, char).kh_put(kh, 5, &absent);
13     ////khash!(uint, char).kh_value(kh, k) = 10;
14     //kh.vals[k] = 'J';
15 
16 //    (*kh)[5] = 'J';
17 //    writeln("Entry value:", (*kh)[5]);
18     
19 //    khash!(uint, char).kh_destroy(kh);
20 
21     auto kh = khash!(uint, char)();
22     kh[5] = 'J';
23     assert(kh[5] == 'J');
24 
25     kh[1] = 'O';
26     kh[99] = 'N';
27 
28     // test: foreach by key
29     /*foreach(k; kh.byKey())
30         writefln("Key: %s", k);*/
31     import std.array : array;
32     assert(kh.byKey().array == [5, 1, 99]);
33 
34     // test: byKey on Empty hash table
35     auto kh_empty = khash!(uint, char)(); // @suppress(dscanner.suspicious.unmodified)
36     assert(kh_empty.byKey.array == []);
37 
38     // test: keytype string
39     auto kh_string = khash!(string, int)();
40     kh_string["test"] = 5;
41     assert( kh_string["test"] == 5 );
42 
43     // test: valtype string
44     auto kh_valstring = khash!(uint, string)();
45     kh_valstring[42] = "Adams";
46     assert( kh_valstring[42] == "Adams" );
47 
48     // test: require
49     const auto fw = kh_string.require("flammenwerfer", 21);
50     assert(fw == 21);
51 
52     // test: kh_hash_equal template type qualifiers and constraints
53     {
54         // test: can instantiate with char* key
55         // (Fails without 'const' qualifier on kh_hash_equal
56         { khash!(char*, int) _; }
57 
58         string s = "Hello";
59         string t = "Hel" ~ "lo";
60         assert( kh_hash!(immutable char).kh_hash_equal(s.ptr, t.ptr) );
61         assert( kh_hash!(string).kh_hash_equal(s, t) );
62     }

Meta