├── .gitignore ├── AUTHORS ├── Makefile ├── README.md ├── bin └── parse-kudb.pl ├── doc ├── Blog.txt ├── andre-test-cases.txt ├── cern-test-cases.txt ├── craig-test-cases.txt ├── heng-test-case.txt ├── nick-test-cases.txt ├── rusty-test-cases.txt └── tessil-test-cases.txt ├── etc ├── Make.rules └── kbench.png ├── share └── latest-x86-64.kudb └── src ├── CDS ├── CDS-grow.c ├── CDS-udb.c ├── Makefile ├── README ├── hash_map.c ├── hash_map.c.ORG ├── hash_map.h ├── hash_map.h.ORG ├── include │ ├── cds.h │ ├── container │ │ ├── hash_map.h │ │ ├── hash_set.h │ │ ├── list.h │ │ ├── priority_queue.h │ │ ├── queue.h │ │ ├── stack.h │ │ ├── tree_map.h │ │ ├── trie.h │ │ └── vector.h │ ├── math │ │ └── hash.h │ └── util.h ├── run-CDS.c └── util.h ├── Makefile ├── amtl ├── Makefile ├── README ├── amtl-grow.cpp ├── amtl-udb.cpp ├── amtl │ ├── am-allocator-policies.h │ ├── am-autoptr.h │ ├── am-bits.h │ ├── am-cxx.h │ ├── am-hashmap.h │ ├── am-hashtable.h │ ├── am-moveable.h │ ├── am-platform.h │ ├── am-raii.h │ ├── am-string.h │ ├── am-type-traits.h │ ├── am-uniqueptr.h │ └── am-utility.h └── run-amtl.cpp ├── apr ├── Makefile ├── README ├── apr-grow.c ├── apr-udb.c ├── apr_hash.c ├── apr_hash.c.ORG ├── apr_hash.h ├── apr_hash.h.ORG └── run-apr.c ├── c-algoritms ├── Makefile ├── README ├── calg-grow.c ├── calg-udb.c ├── compare-int.c ├── compare-int.h ├── compare-pointer.c ├── compare-pointer.h ├── compare-string.c ├── compare-string.h ├── hash-int.c ├── hash-int.h ├── hash-pointer.c ├── hash-pointer.h ├── hash-string.c ├── hash-string.h ├── hash-table.c ├── hash-table.h └── run-c-alg.c ├── c-hashtable ├── Makefile ├── README ├── cwc-grow.c ├── cwc-udb.c ├── hashtable.c ├── hashtable.c.ORG ├── hashtable.h ├── hashtable_private.h └── run-cwc.c ├── ccan ├── Makefile ├── README ├── ccan-grow.c ├── ccan-udb.c ├── config.h ├── hash.c ├── hash.h ├── hash.h.ORG ├── htable.c ├── htable.c.ORG ├── htable.h └── run-ccan-htable.c ├── cfu ├── Makefile ├── README ├── cfu-grow.c ├── cfu-udb.c ├── cfu.h ├── cfuhash.c ├── cfuhash.c.ORG ├── cfuhash.h └── run-cfu.c ├── eastl ├── EASTL │ ├── EABase │ │ ├── config │ │ │ ├── eacompiler.h │ │ │ ├── eacompilertraits.h │ │ │ └── eaplatform.h │ │ ├── eabase.h │ │ ├── eahave.h │ │ ├── nullptr.h │ │ └── version.h │ ├── algorithm.h │ ├── allocator.h │ ├── functional.h │ ├── hash_map.h │ ├── initializer_list.h │ ├── internal │ │ ├── allocator_traits_fwd_decls.h │ │ ├── config.h │ │ ├── copy_help.h │ │ ├── fill_help.h │ │ ├── function.h │ │ ├── functional_base.h │ │ ├── generic_iterator.h │ │ ├── hashtable.h │ │ ├── integer_sequence.h │ │ ├── mem_fn.h │ │ ├── move_help.h │ │ ├── tuple_fwd_decls.h │ │ ├── type_compound.h │ │ ├── type_fundamental.h │ │ ├── type_pod.h │ │ ├── type_properties.h │ │ └── type_transformations.h │ ├── iterator.h │ ├── numeric_limits.h │ ├── random.h │ ├── type_traits.h │ └── utility.h ├── Makefile ├── README ├── eastl-grow.cpp ├── eastl-udb.cpp ├── hashtable.cpp └── run-ea.cpp ├── emilib ├── Makefile ├── grow.cpp ├── hash_map.hpp ├── loguru.hpp ├── run-emilib.cpp └── udb.cpp ├── gcc-libiberty ├── Makefile ├── README ├── ansidecl.h ├── gcc-grow.c ├── gcc-udb.c ├── hashtab.c ├── hashtab.c.ORG ├── hashtab.h └── run-gcc.c ├── generic-c-hashmap ├── Makefile ├── README ├── gc-grow.c ├── gc-udb.c ├── hashmap.h └── run-gc-hashmap.c ├── ghthash ├── Makefile ├── README ├── ght-grow.c ├── ght-udb.c ├── ght_hash_table.h ├── hash_functions.c ├── hash_table.c └── run-ght.c ├── google-c ├── Makefile ├── README ├── google-dense-grow.c ├── google-dense-udb.c ├── google-sparse-grow.c ├── google-sparse-udb.c ├── libchash.c ├── libchash.c.ORG ├── libchash.h ├── libchash.h.ORG ├── run-dense.c └── run-sparse.c ├── hashit ├── Makefile ├── README ├── hashit-chain-grow.c ├── hashit-chain-udb.c ├── hashit-open-grow.c ├── hashit-open-udb.c ├── hashit-overflow-grow.c ├── hashit-overflow-udb.c ├── hashit.c ├── hashit.h ├── hfunctions.c ├── hfunctions.h ├── run-chain.c ├── run-open.c └── run-overflow.c ├── hhash ├── Makefile ├── README ├── hhash-udb.c ├── hhash.c ├── hhash.h ├── hhmap.c ├── hhmap.h ├── mach.c └── run-hhash.c ├── htable ├── Makefile ├── README ├── htable-grow.c ├── htable-udb.c ├── htable.h ├── list.h └── run-htable.c ├── judy-template ├── Makefile ├── README ├── judy.c ├── judy.h ├── judyLArray.h ├── judyLArray.h.ORG ├── judySArray.h └── run-jat.cpp ├── judyarray ├── Makefile ├── README ├── judy64nb.c ├── judy64nb.c.ORG ├── judyarray.h └── run-ja.c ├── khash ├── Makefile ├── README ├── khash-grow.c ├── khash-udb.c ├── khash.h └── run-khash.c ├── libevent ├── Makefile ├── README ├── ht-internal.h ├── libevent-grow.c ├── libevent-udb.c └── run-le.c ├── ltable ├── Makefile ├── ltable-grow.c ├── ltable-udb.c ├── ltable.c ├── ltable.h ├── ltable.h.ORG └── run-ltable.c ├── lua-table ├── Makefile ├── hash.c ├── hash.h ├── lua-table-grow.c ├── lua-table-udb.c ├── run-lua-table.c ├── table.c └── table.h ├── mct ├── Makefile ├── README ├── mct-closed-grow.cpp ├── mct-closed-udb.cpp ├── mct-linked-grow.cpp ├── mct-linked-udb.cpp ├── mct │ ├── config.hpp │ ├── hash-map.hpp │ ├── impl │ │ ├── closed-hash-table.hpp │ │ ├── optimization.hpp │ │ └── utils.hpp │ └── intrusiveness.hpp ├── run-mct-closed.cpp └── run-mct-linked.cpp ├── oddou-hashmap ├── Makefile ├── grow.cpp ├── hashmap.hpp ├── pool.hpp ├── run-oddou.cpp └── udb.cpp ├── python ├── Makefile ├── README ├── hashtable.c ├── hashtable.c.ORG ├── hashtable.h ├── hashtable.h.ORG ├── pyhash.c ├── pyhash.c.ORG ├── pyhash.h ├── pyhash.h.ORG ├── python-grow.c ├── python-udb.c └── run-python.c ├── rdestl ├── Makefile ├── algorithm.h ├── allocator.h ├── functional.h ├── hash.h ├── hash_map.h ├── int_to_type.h ├── iterator.h ├── pair.h ├── rde-grow.cpp ├── rde-udb.cpp ├── rdestl_common.h ├── run-rde.cpp ├── type_traits.h └── utility.h ├── redis ├── Makefile ├── atomicvar.h ├── config.h ├── dict.c ├── dict.c.ORG ├── dict.h ├── fmacros.h ├── grow.c ├── run-redis.c ├── udb.c ├── zmalloc.c └── zmalloc.h ├── rigtorp-hashmap ├── HashMap.h ├── Makefile ├── grow.cpp ├── run-rigtorp.cpp └── udb.cpp ├── ruby-st ├── Makefile ├── README ├── ccan │ ├── build_assert │ │ └── build_assert.h │ ├── check_type │ │ └── check_type.h │ ├── config.h │ ├── container_of │ │ └── container_of.h │ ├── list │ │ └── list.h │ └── str │ │ ├── str.h │ │ └── str_debug.h ├── ruby-st-grow.c ├── ruby-st-udb.c ├── run-ruby-st.c ├── st.c ├── st.c.ORG ├── st.h └── st.h.ORG ├── run-it ├── AUTHORS ├── Makefile ├── benchmark.c ├── benchmark.h ├── rhash.h ├── run-it.c ├── runlib.c └── runlib.h ├── sglib ├── Makefile ├── README ├── run-sglib.c ├── sglib-grow.c ├── sglib-udb.c └── sglib.h ├── st ├── Makefile ├── ORG-st.c ├── ORG-st.h ├── README ├── run-st.c ├── st-grow.c ├── st-udb.c ├── st.c └── st.h ├── stb ├── Makefile ├── README ├── run-stb.c ├── stb-grow.c ├── stb-udb.c ├── stb.h └── stb.h.ORG ├── sys-LuaHashMap ├── LuaHashMap-grow.c ├── LuaHashMap-udb.c ├── LuaHashMap.c ├── LuaHashMap.h ├── Makefile ├── README └── run-luahashmap.c ├── sys-Qt ├── Makefile ├── qt-hash-grow.cpp ├── qt-hash-udb.cpp ├── qt-map-grow.cpp ├── qt-map-udb.cpp ├── run-hash.cpp └── run-map.cpp ├── sys-apr ├── Makefile ├── README ├── apr-grow.c ├── apr-udb.c └── run-apr-lib.c ├── sys-boost ├── Makefile ├── boost-grow.cpp ├── boost-udb.cpp └── run-unordered-map.cpp ├── sys-gcc-stl ├── Makefile ├── g++-map-grow.cpp ├── g++-map-udb.cpp ├── g++-unordered-grow.cpp ├── g++-unordered-udb.cpp ├── run-map.cpp └── run-unordered-map.cpp ├── sys-glib ├── Makefile ├── README ├── glib-grow.c ├── glib-udb.c └── run-glib.c ├── sys-judy ├── Makefile ├── README ├── judy-grow.c ├── judy-udb.c └── run-judy.c ├── sys-perl ├── Makefile ├── README ├── perl-grow.c ├── perl-udb.c └── run-perl.c ├── sys-python ├── Makefile ├── README ├── python-grow.c ├── python-udb.c └── run-python.c ├── sys-ruby ├── Makefile ├── README └── run-ruby.c ├── sys-sparsehash ├── Makefile ├── dense-grow.cpp ├── dense-udb.cpp ├── run-dense.cpp ├── run-sparse.cpp ├── sparse-grow.cpp └── sparse-udb.cpp ├── sys-tcl ├── Makefile ├── README ├── run-tcl.c ├── tcl-grow.c └── tcl-udb.c ├── tommyds ├── Makefile ├── README ├── objs.c ├── run-dynamic.c ├── run-fixed.c ├── run-linear.c ├── tommyds-dynamic-grow.c ├── tommyds-dynamic-udb.c ├── tommyds-fixed-grow.c ├── tommyds-fixed-udb.c ├── tommyds-linear-grow.c ├── tommyds-linear-udb.c ├── tommyhash.c ├── tommyhash.h ├── tommyhashdyn.c ├── tommyhashdyn.h ├── tommyhashlin.c ├── tommyhashlin.h ├── tommyhashtbl.c ├── tommyhashtbl.h ├── tommylist.h └── tommytypes.h ├── ulib ├── Makefile ├── README ├── hash_chain_prot.h ├── hash_open_prot.h ├── run-ulib-open.c ├── ulib-open-grow.c ├── ulib-open-udb.c └── util_algo.h └── uthash ├── Makefile ├── README ├── run-uthash.c ├── uthash-grow.c ├── uthash-udb.c └── uthash.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Executables 2 | run-* 3 | 4 | # Automatically generated C sources 5 | 6 | # Libraries 7 | *.a 8 | 9 | # Shared objects 10 | *.so 11 | 12 | # Object files 13 | *.o 14 | 15 | # Dependency files 16 | *.M 17 | 18 | # Backup files 19 | *~ 20 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | -------------------------------------------------------------------------------- /doc/Blog.txt: -------------------------------------------------------------------------------- 1 | Sean Barrett 2003 http://nothings.org/computer/judy (updated 2011) 2 | Maciej Sinilo 2007 http://msinilo.pl/blog/?cat=6 (updated 2013) 3 | Heng Li (Attractive Chaos) 2008 http://attractivechaos.wordpress.com/2008/08/28/comparison-of-hash-table-libraries 4 | Heng Li (Attractive Chaos) 2008 http://attractivechaos.wordpress.com/2008/10/07/another-look-at-my-old-benchmark 5 | Nick Welch (incise.org) 2010 http://incise.org/hash-table-benchmarks.html 6 | Rusty Russell (ccan) 2010 http://rusty.ozlabs.org/?p=153 7 | Jeff Preshing 2011 http://preshing.com/20110603/hash-table-performance-tests 8 | Eric Wing 2012 http://playcontrol.net/opensource/LuaHashMap/benchmarks.html 9 | Andrea Mazzoleni 2013 http://www.tommyds.it/doc/benchmark 10 | Fredrik Widlund (lonewolfer) 2014 http://lonewolfer.wordpress.com/2014/03/13/benchmarking-hash-table-implementations-in-different-languages 11 | Fredrik Widlund (lonewolfer) 2015 http://lonewolfer.wordpress.com/2015/02/07/benchmarking-string-hash-tables 12 | 13 | Tessil 2016 http://tessil.github.io/2016/08/29/benchmark-hopscotch-map.html -------------------------------------------------------------------------------- /doc/andre-test-cases.txt: -------------------------------------------------------------------------------- 1 | Author: Andre' Medeiros (me@andremedeiros.info) 2 | 3 | Test case implemented in hash_benchmark (https://github.com/andremedeiros/hash_benchmark) 4 | ========================================================================================= 5 | 6 | * Writes 7 | * Reads 8 | * Random reads 9 | * Non-existant key reads 10 | * Write & Delete (same key) 11 | -------------------------------------------------------------------------------- /doc/cern-test-cases.txt: -------------------------------------------------------------------------------- 1 | Author: Tobias Kappe' (tobias.kappe@cern.c) 2 | 3 | Test cases described in: 4 | ======================== 5 | https://gitlab.cern.ch/dss/map-benchmarks 6 | 7 | SET - Adds a random key/value-pair to the hashtable. Note that the key may already exist in the hashtable 8 | GET - Retrieves a random value from the hashtable, using a (randomly selected) key that is already in the hashtable 9 | GET_RANDOM - Retrieves a randomly generated key from the hashtable. Chances are this key does not exist 10 | DELETE - Like get, but delete the key 11 | DELETE_RANDOM - Like get-random, but delete the key 12 | ITERATE - Iterates over all entries in the hashtable (in arbitrary order) 13 | -------------------------------------------------------------------------------- /doc/craig-test-cases.txt: -------------------------------------------------------------------------------- 1 | Author: Craig Silverstein (csilvers@khanacademy.org) 2 | 3 | Test case implemented in Google sparse hash (time_hash_map.cc) 4 | ============================================================== 5 | 6 | map_grow: add N elements to the hash map 7 | map_predict/grow: reserve space first, then add elements 8 | map_replace: add elements, overwrite their values in another loop 9 | map_fetch_random: fetch all elements one-by-one (indexing by random key), N elements in map 10 | map_fetch_sequential: fetch all elements one-by-one (indexing by key), N elements in map 11 | map_fetch_empty: same, on empty map 12 | map_remove: remove all elements from map, one by one, N elements in map 13 | map_toggle: in every iteration add element, then erase it immediately 14 | map_iterate: iterate over all the hash map 15 | -------------------------------------------------------------------------------- /doc/heng-test-case.txt: -------------------------------------------------------------------------------- 1 | Test case described in: 2 | ======================= 3 | Benchmark of Dictionary Structures 4 | https://lh3lh3.users.sourceforge.net/udb.shtml 5 | 6 | 1) Generate a random array of 5 million elements with 1,25 million (exactly 1,227,176) of distinct integer/string keys 7 | 2) To benchmark hash table with string keys, the same integer array is converted to char* array using sprintf() 8 | 3) Each element is then tested whether it is present in the hash table 9 | * delete if present 10 | * add if absent 11 | 4) 625,792 distinct keys will be left in the hash after this process 12 | 5) Evaluate time/memory spent for the execution of the test 13 | 14 | -------------------------------------------------------------------------------- /doc/nick-test-cases.txt: -------------------------------------------------------------------------------- 1 | Author: Nick Welch (nick@incise.org) 2 | 3 | Test cases described in: 4 | ======================== 5 | http://incise.org/hash-table-benchmarks.html 6 | 7 | Sequential Inserts: measure how long it takes to insert a contiguous series of integer keys 8 | Random Inserts: measure how long it takes to insert a random series of integer keys, with some duplicates 9 | Deletion: measure how long it takes to delete a contiguous series of integer keys, which are all ensured to exist 10 | 11 | Warning: add these 12 | Looking up keys, in order and random, in tables that have been built in order and randomly. 13 | -------------------------------------------------------------------------------- /doc/rusty-test-cases.txt: -------------------------------------------------------------------------------- 1 | Author: Rusty Russell (rusty@rustcorp.com.au) 2 | 3 | Test case implemented in htable/tools (hsearchspeed.c) 4 | ====================================================== 5 | 6 | Initial insert 7 | Linear hit 8 | Linear miss 9 | Random hit 10 | Delete 11 | Reinsert 12 | Delete Half 13 | Add Half 14 | -------------------------------------------------------------------------------- /doc/tessil-test-cases.txt: -------------------------------------------------------------------------------- 1 | insert_random_shuffle_range 2 | read_random_shuffle_range 3 | insert_random_full 4 | insert_random_full_reserve 5 | read_random_full 6 | read_miss_random_full 7 | read_random_full_after_delete 8 | iteration_random_full 9 | delete_random_full 10 | insert_small_string 11 | insert_small_string_reserve 12 | read_small_string 13 | read_miss_small_string 14 | read_small_string_after_delete 15 | delete_small_string 16 | insert_string 17 | insert_string_reserve 18 | read_string 19 | read_miss_string 20 | read_string_after_delete 21 | delete_string 22 | -------------------------------------------------------------------------------- /etc/kbench.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcarbone/kbench/4ce1c71a2c44c969130fc892d282f4ccc85a508d/etc/kbench.png -------------------------------------------------------------------------------- /src/CDS/CDS-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | HashMap * ht = HashMapInit (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | HashMapPut (ht, (void *) (intptr_t) keys [i], (void *) (intptr_t) keys [i]); 10 | 11 | count = HashMapSize (ht); 12 | 13 | HashMapDeinit (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | HashMap * ht = HashMapInit (); 22 | unsigned i; 23 | unsigned count; 24 | 25 | /* Set the custom hash value generator and key comparison functions */ 26 | HashMapSetHash (ht, HashKey); 27 | HashMapSetCompare (ht, CompareKey); 28 | 29 | for (i = 0; i < n; i ++) 30 | HashMapPut (ht, keys [i], & i); 31 | 32 | count = HashMapSize (ht); 33 | 34 | HashMapDeinit (ht); 35 | 36 | return count; 37 | } 38 | -------------------------------------------------------------------------------- /src/CDS/CDS-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | HashMap * ht = HashMapInit (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (HashMapContain (ht, (void *) (intptr_t) keys [i])) 11 | HashMapRemove (ht, (void *) (intptr_t) keys [i]); 12 | else 13 | HashMapPut (ht, (void *) (intptr_t) keys [i], (void *) (intptr_t) keys [i]); 14 | } 15 | 16 | count = HashMapSize (ht); 17 | 18 | HashMapDeinit (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | HashMap * ht = HashMapInit (); 27 | unsigned i; 28 | unsigned count; 29 | 30 | /* Set the custom hash value generator and key comparison functions */ 31 | HashMapSetHash (ht, HashKey); 32 | HashMapSetCompare (ht, CompareKey); 33 | 34 | for (i = 0; i < n; i ++) 35 | { 36 | if (HashMapContain (ht, keys [i])) 37 | HashMapRemove (ht, keys [i]); 38 | else 39 | HashMapPut (ht, keys [i], & i); 40 | } 41 | 42 | count = HashMapSize (ht); 43 | 44 | HashMapDeinit (ht); 45 | 46 | return count; 47 | } 48 | -------------------------------------------------------------------------------- /src/CDS/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hash_map.c 3 | LIB = lib-kbench-CDS.a 4 | MAINSRCS = run-CDS.c 5 | 6 | include ../../etc/Make.rules 7 | -------------------------------------------------------------------------------- /src/CDS/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name CDS 6 | Module HashMap 7 | Author ZongXian Shen (andy.zsshen@gmail.com) 8 | Description LibCDS - a set of uniform C APIs for data structure manipulation 9 | Download http://github.com/ZSShen/C-Common-Data-Structures 10 | Date 2015, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | 18 | - hash_map.h 19 | - hash_map.c 20 | - util.h 21 | 22 | The following files have been subject to modifications in order to compile them as a standalone module: 23 | - hash_map.h 24 | - hash_map.c 25 | 26 | Moreover I fixed 1 warning message at line 182 of hash_map.c about 'data' may be used unitialized. 27 | -------------------------------------------------------------------------------- /src/CDS/include/cds.h: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | #include "container/vector.h" 3 | #include "container/list.h" 4 | #include "container/tree_map.h" 5 | #include "container/hash_map.h" 6 | #include "container/hash_set.h" 7 | #include "container/stack.h" 8 | #include "container/queue.h" 9 | #include "container/priority_queue.h" 10 | #include "container/trie.h" 11 | #include "math/hash.h" -------------------------------------------------------------------------------- /src/CDS/include/util.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_H_ 2 | #define _UTIL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | /** The key value pair for associative data structures. */ 14 | typedef struct _Pair { 15 | void* key; 16 | void* value; 17 | } Pair; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/CDS/run-CDS.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "hash_map.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | static unsigned HashDjb2 (char * key) 9 | { 10 | unsigned hash = 5381; 11 | int c; 12 | 13 | while ((c = * key ++)) 14 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 15 | 16 | return hash; 17 | } 18 | 19 | 20 | static unsigned HashKey (void * key) 21 | { 22 | return HashDjb2 ((char *) key); 23 | } 24 | 25 | 26 | static int CompareKey (void * lhs, void * rhs) 27 | { 28 | return strcmp ((char *) lhs, (char *) rhs); 29 | } 30 | 31 | 32 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 33 | 34 | #include "CDS-udb.c" 35 | #include "CDS-grow.c" 36 | 37 | 38 | int main (int argc, char * argv []) 39 | { 40 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 41 | } 42 | -------------------------------------------------------------------------------- /src/CDS/util.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIL_H_ 2 | #define _UTIL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | /** The key value pair for associative data structures. */ 14 | typedef struct _Pair { 15 | void* key; 16 | void* value; 17 | } Pair; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/amtl/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-amtl.cpp 3 | 4 | C++FLAGS = -Wno-sign-compare 5 | SYSLIBS += -lstdc++ 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/amtl/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Sep 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name amtl 6 | Module hashmap 7 | Author David Anderson and AlliedModders LLC 8 | Description AlliedModders's' C++ Template Library 9 | Download http://github.com/alliedmodders/amtl 10 | Date 2013, 2016 11 | Language C++ 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | - amtl/am-hashmap.h 18 | - amtl/am-hashtable.h 19 | 20 | - amtl/am-allocator-policies.h 21 | - amtl/am-autoptr.h 22 | - amtl/am-bits.h 23 | - amtl/am-cxx.h 24 | - amtl/am-moveable.h 25 | - amtl/am-platform.h 26 | - amtl/am-raii.h 27 | - amtl/am-string.h 28 | - amtl/am-type-traits.h 29 | - amtl/am-uniqueptr.h 30 | - amtl/am-utility.h 31 | -------------------------------------------------------------------------------- /src/amtl/amtl-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | ht -> init (); 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | hashtable_int_t::Insert hit = ht -> findForAdd (keys [i]); 13 | ht -> add (hit, keys [i], i + 1); 14 | } 15 | 16 | count = ht -> elements (); 17 | 18 | delete ht; 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned grow_str (unsigned n, char ** keys) 25 | { 26 | hashtable_str_t * ht = new hashtable_str_t; 27 | unsigned i; 28 | unsigned count; 29 | 30 | ht -> init (); 31 | 32 | for (i = 0; i < n; i ++) 33 | { 34 | hashtable_str_t::Insert hit = ht -> findForAdd (keys [i]); 35 | if (hit . found ()) 36 | ht -> remove (hit); 37 | else 38 | ht -> add (hit, AString (keys [i]), i); 39 | } 40 | 41 | count = ht -> elements (); 42 | 43 | delete ht; 44 | 45 | return count; 46 | } 47 | -------------------------------------------------------------------------------- /src/amtl/amtl-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | ht -> init (); 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | hashtable_int_t::Insert hit = ht -> findForAdd (keys [i]); 13 | if (hit . found ()) 14 | ht -> remove (hit); 15 | else 16 | ht -> add (hit, keys [i], i); 17 | } 18 | 19 | count = ht -> elements (); 20 | 21 | delete ht; 22 | 23 | return count; 24 | } 25 | 26 | 27 | unsigned udb_str (unsigned n, char ** keys) 28 | { 29 | hashtable_str_t * ht = new hashtable_str_t; 30 | unsigned i; 31 | unsigned count; 32 | 33 | ht -> init (); 34 | 35 | for (i = 0; i < n; i ++) 36 | { 37 | hashtable_str_t::Insert hit = ht -> findForAdd (keys [i]); 38 | if (hit . found ()) 39 | ht -> remove (hit); 40 | else 41 | ht -> add (hit, AString (keys [i]), i); 42 | } 43 | 44 | count = ht -> elements (); 45 | 46 | delete ht; 47 | 48 | return count; 49 | } 50 | -------------------------------------------------------------------------------- /src/amtl/run-amtl.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "amtl/am-hashmap.h" 7 | #include "amtl/am-string.h" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | using namespace ke; 12 | 13 | struct Policy 14 | { 15 | static inline uint32_t hash (unsigned key) 16 | { 17 | return HashInt64 (key); 18 | } 19 | 20 | static inline uint32_t hash (const char * key) 21 | { 22 | return FastHashCharSequence (key, strlen (key)); 23 | } 24 | 25 | static inline bool matches (unsigned key1, unsigned key2) 26 | { 27 | return key1 == key2; 28 | } 29 | 30 | static inline bool matches (const char * find, const AString & key) 31 | { 32 | return key . compare (find) == 0; 33 | } 34 | }; 35 | 36 | typedef ke::HashMap hashtable_int_t; 37 | typedef ke::HashMap hashtable_str_t; 38 | 39 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 40 | 41 | #include "amtl-udb.cpp" 42 | #include "amtl-grow.cpp" 43 | 44 | 45 | int main (int argc, char * argv []) 46 | { 47 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 48 | } 49 | -------------------------------------------------------------------------------- /src/apr/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = apr_hash.c 3 | LIB = lib-kbench-apr.a 4 | MAINSRCS = run-apr.c 5 | 6 | include ../../etc/Make.rules 7 | -------------------------------------------------------------------------------- /src/apr/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name apr 6 | Module hashtable 7 | Author Apache Software Foundation (ASF) 8 | Description Apache Portable Runtime Library 9 | Download http://apache.org 10 | Date 2011, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest version available at: 17 | http://apache.panu.it/apr/apr-1.5.2.tar.gz 18 | 19 | - apr_hash.h 20 | - apr_hash.c 21 | 22 | Both have been subject to modifications in order to compile the files as a standalone module. 23 | 24 | Moreover I fixed 2 memory leaks: 25 | ! defined function apr_hash_done() to free ht->array and ht pointer itself 26 | ! in apr_hash_set() the entry just deleted pointed to by the variable 'old' was not freed 27 | -------------------------------------------------------------------------------- /src/apr/apr-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | apr_hash_t * ht = apr_hash_make (NULL); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | apr_hash_set (ht, & keys [i], sizeof (keys [i]), & keys [i]); 10 | 11 | count = apr_hash_count (ht); 12 | 13 | apr_hash_done (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | apr_hash_t * ht = apr_hash_make (NULL); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | apr_hash_set (ht, keys [i], strlen (keys [i]), keys [i]); 27 | 28 | count = apr_hash_count (ht); 29 | 30 | apr_hash_done (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/apr/apr-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | apr_hash_t * ht = apr_hash_make (NULL); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (apr_hash_get (ht, & keys [i], sizeof (keys [i]))) 11 | apr_hash_del (ht, & keys [i], sizeof (keys [i])); 12 | else 13 | apr_hash_set (ht, & keys [i], sizeof (keys [i]), & keys [i]); 14 | } 15 | 16 | count = apr_hash_count (ht); 17 | 18 | apr_hash_done (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | apr_hash_t * ht = apr_hash_make (NULL); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (apr_hash_get (ht, keys [i], strlen (keys [i]))) 33 | apr_hash_del (ht, keys [i], strlen (keys [i])); 34 | else 35 | apr_hash_set (ht, keys [i], strlen (keys [i]), keys [i]); 36 | } 37 | 38 | count = apr_hash_count (ht); 39 | 40 | apr_hash_done (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/apr/run-apr.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "apr_hash.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | #define apr_hash_del(x, y, z) apr_hash_set(x, y, z, NULL) 9 | 10 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 11 | 12 | #include "apr-udb.c" 13 | #include "apr-grow.c" 14 | 15 | 16 | int main (int argc, char * argv []) 17 | { 18 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 19 | } 20 | -------------------------------------------------------------------------------- /src/c-algoritms/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hash-table.c 3 | SRCS += hash-int.c 4 | SRCS += hash-string.c 5 | SRCS += hash-pointer.c 6 | SRCS += compare-int.c 7 | SRCS += compare-string.c 8 | SRCS += compare-pointer.c 9 | LIB = lib-kbench-c-alg.a 10 | MAINSRCS = run-c-alg.c 11 | 12 | include ../../etc/Make.rules 13 | -------------------------------------------------------------------------------- /src/c-algoritms/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name C Algorithms 6 | Module Hash table 7 | Author Simon Howard (fraggle@gmail.com) 8 | Description A collection of common Computer Science algorithms 9 | Download http://github.com/fragglet/c-algorithms 10 | Date 2005-2008 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | - hash-table.h 18 | - hash-table.c 19 | 20 | - hash-int.h 21 | - hash-string.h 22 | - hash-pointer.h 23 | - compare-int.h 24 | - compare-string.h 25 | - compare-pointer.h 26 | - hash-int.c 27 | - hash-string.c 28 | - hash-pointer.c 29 | - compare-int.c 30 | - compare-string.c 31 | - compare-pointer.c 32 | -------------------------------------------------------------------------------- /src/c-algoritms/calg-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | HashTable * ht = hash_table_new (int_hash, int_equal); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | hash_table_insert (ht, (unsigned *) & keys [i], & i); 10 | 11 | count = hash_table_num_entries (ht); 12 | 13 | hash_table_free (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | HashTable * ht = hash_table_new (string_hash, string_equal); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | hash_table_insert (ht, keys [i], & i); 27 | 28 | count = hash_table_num_entries (ht); 29 | 30 | hash_table_free (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/c-algoritms/calg-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | HashTable * ht = hash_table_new (int_hash, int_equal); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (hash_table_lookup (ht, (unsigned *) & keys [i])) 11 | hash_table_remove (ht, (unsigned *) & keys [i]); 12 | else 13 | hash_table_insert (ht, (unsigned *) & keys [i], & i); 14 | } 15 | 16 | count = hash_table_num_entries (ht); 17 | 18 | hash_table_free (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | HashTable * ht = hash_table_new (string_hash, string_equal); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (hash_table_lookup (ht, keys [i])) 33 | hash_table_remove (ht, keys [i]); 34 | else 35 | hash_table_insert (ht, keys [i], & i); 36 | } 37 | 38 | count = hash_table_num_entries (ht); 39 | 40 | hash_table_free (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/c-algoritms/compare-pointer.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2005-2008, Simon Howard 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice appear 8 | in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | */ 20 | 21 | #include "compare-pointer.h" 22 | 23 | /* Comparison functions for a generic void pointer */ 24 | 25 | int pointer_equal(void *location1, void *location2) 26 | { 27 | return location1 == location2; 28 | } 29 | 30 | int pointer_compare(void *location1, void *location2) 31 | { 32 | if (location1 < location2) { 33 | return -1; 34 | } else if (location1 > location2) { 35 | return 1; 36 | } else { 37 | return 0; 38 | } 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/c-algoritms/hash-int.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2005-2008, Simon Howard 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice appear 8 | in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | */ 20 | 21 | #include "hash-int.h" 22 | 23 | /* Hash function for a pointer to an integer */ 24 | 25 | unsigned int int_hash(void *vlocation) 26 | { 27 | int *location; 28 | 29 | location = (int *) vlocation; 30 | 31 | return (unsigned int) *location; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/c-algoritms/hash-pointer.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2005-2008, Simon Howard 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice appear 8 | in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR 14 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 16 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | 19 | */ 20 | 21 | #include 22 | 23 | #include "hash-pointer.h" 24 | 25 | /* Hash function for a generic pointer */ 26 | 27 | unsigned int pointer_hash(void *location) 28 | { 29 | return (unsigned int) (unsigned long) location; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/c-algoritms/run-c-alg.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "hash-table.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | #include "hash-int.h" 9 | #include "compare-int.h" 10 | #include "hash-string.h" 11 | #include "compare-string.h" 12 | 13 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 14 | 15 | #include "calg-udb.c" 16 | #include "calg-grow.c" 17 | 18 | 19 | int main (int argc, char * argv []) 20 | { 21 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 22 | } 23 | -------------------------------------------------------------------------------- /src/c-hashtable/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hashtable.c 3 | LIB = lib-kbench-cwc.a 4 | MAINSRCS = run-cwc.c 5 | 6 | WFLAGS = -Wno-discarded-qualifiers 7 | SYSLIBS += -lm 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/c-hashtable/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name c-hashtable 6 | Module c-hashtable 7 | Author Christopher Clark (christopher.clark@cl.cam.ac.uk) 8 | Description C Hash Table - hash table data structure in C 9 | Download http://github.com/davidar/c-hashtable 10 | Date 2002, 2007 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from a git mirror by David A Roberts available at: 17 | http://github.com/davidar/c-hashtable 18 | 19 | - hashtable.h 20 | - hashtable.c 21 | - hashtable_private.h 22 | 23 | 24 | No modification was needed to compile the files as a standalone module. 25 | 26 | The following modification was needed to fix a bug: 27 | - hashtable.c => don't free the key that was not malloced in the library during entry setup 28 | 29 | 30 | Hash table data structure in C by Christopher Clark was originally at http://www.cl.cam.ac.uk/~cwc22/hashtable 31 | -------------------------------------------------------------------------------- /src/c-hashtable/cwc-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | struct hashtable * ht = create_hashtable (0, hash_int_key_fn, eq_int_key_fn); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | hashtable_insert (ht, & keys [i], & i); 10 | 11 | count = hashtable_count (ht); 12 | 13 | hashtable_destroy (ht, 0); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | struct hashtable * ht = create_hashtable (0, hash_str_key_fn, eq_str_key_fn); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | hashtable_insert (ht, keys [i], & i); 27 | 28 | count = hashtable_count (ht); 29 | 30 | hashtable_destroy (ht, 0); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/c-hashtable/cwc-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | struct hashtable * ht = create_hashtable (0, hash_int_key_fn, eq_int_key_fn); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (hashtable_search (ht, & keys [i])) 11 | hashtable_remove (ht, & keys [i]); 12 | else 13 | hashtable_insert (ht, & keys [i], & i); 14 | } 15 | 16 | count = hashtable_count (ht); 17 | 18 | hashtable_destroy (ht, 0); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | struct hashtable * ht = create_hashtable (0, hash_str_key_fn, eq_str_key_fn); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (hashtable_search (ht, keys [i])) 33 | hashtable_remove (ht, keys [i]); 34 | else 35 | hashtable_insert (ht, keys [i], & i); 36 | } 37 | 38 | count = hashtable_count (ht); 39 | 40 | hashtable_destroy (ht, 0); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/c-hashtable/run-cwc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "hashtable.h" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #include "rhash.h" 11 | 12 | static unsigned hash_int_key_fn (void * key) 13 | { 14 | return java_hash (* (unsigned *) key); 15 | } 16 | 17 | 18 | static unsigned hash_str_key_fn (void * key) 19 | { 20 | return python_hash (key); 21 | } 22 | 23 | 24 | static int eq_int_key_fn (void * key1, void * key2) 25 | { 26 | return * (unsigned *) key1 == * (unsigned *) key2; 27 | } 28 | 29 | 30 | static int eq_str_key_fn (void * key1, void * key2) 31 | { 32 | return ! strcmp (key1, key2); 33 | } 34 | 35 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 36 | 37 | #include "cwc-udb.c" 38 | #include "cwc-grow.c" 39 | 40 | 41 | int main (int argc, char * argv []) 42 | { 43 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 44 | } 45 | -------------------------------------------------------------------------------- /src/ccan/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = htable.c 3 | SRCS += hash.c 4 | LIB = lib-kbench-ccan-htable.a 5 | MAINSRCS = run-ccan-htable.c 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/ccan/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name ccan 6 | Module htable 7 | Author Rusty Russell (rusty@rustcorp.com.au) 8 | Description Hash table included in CCAN (C Code Archive Network) 9 | Download http://github.com/rustyrussell/ccan 10 | Date 2010, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | The following sources files were locally copied from latest git version: 16 | - htable.h 17 | - htable.c 18 | - hash.h 19 | - hash.c 20 | 21 | The following modifications were needed to compile the files as a standalone module: 22 | 1. config.h was locally edited to define symbols required by htable.h 23 | (only COLD is really mandatory and must be defined in config.h) 24 | 2. htable.c was modified in order to avoid dependency from compiler.h 25 | 3. hash.h was modified in order to avoid dependency from build_assert.h 26 | -------------------------------------------------------------------------------- /src/ccan/ccan-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | struct htable * ht = calloc (1, sizeof (* ht)); 5 | unsigned i; 6 | unsigned count; 7 | 8 | htable_init (ht, hash_int_fn, NULL); 9 | 10 | for (i = 0; i < n; i ++) 11 | htable_add (ht, keys [i], & keys [i]); 12 | 13 | count = htable_count (ht); 14 | 15 | htable_clear (ht); 16 | free (ht); 17 | 18 | return count; 19 | } 20 | 21 | 22 | unsigned grow_str (unsigned n, char ** keys) 23 | { 24 | struct htable * ht = calloc (1, sizeof (* ht)); 25 | unsigned i; 26 | unsigned count; 27 | 28 | htable_init (ht, hash_str_fn, NULL); 29 | 30 | for (i = 0; i < n; i ++) 31 | htable_add (ht, hash_string (keys [i]), keys [i]); 32 | 33 | count = htable_count (ht); 34 | 35 | htable_clear (ht); 36 | free (ht); 37 | 38 | return count; 39 | } 40 | -------------------------------------------------------------------------------- /src/ccan/ccan-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | struct htable * ht = calloc (1, sizeof (* ht)); 5 | unsigned i; 6 | unsigned count; 7 | 8 | htable_init (ht, hash_int_fn, NULL); 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | unsigned * hit = htable_get (ht, keys [i], eq_int_fn, & keys [i]); 13 | if (hit) 14 | htable_del (ht, keys [i], hit); 15 | else 16 | htable_add (ht, keys [i], & keys [i]); 17 | } 18 | 19 | count = htable_count (ht); 20 | 21 | htable_clear (ht); 22 | free (ht); 23 | 24 | return count; 25 | } 26 | 27 | 28 | unsigned udb_str (unsigned n, char ** keys) 29 | { 30 | struct htable * ht = calloc (1, sizeof (* ht)); 31 | unsigned i; 32 | unsigned count; 33 | 34 | htable_init (ht, hash_str_fn, NULL); 35 | 36 | for (i = 0; i < n; i ++) 37 | { 38 | unsigned * hit = htable_get (ht, hash_string (keys [i]), eq_str_fn, keys [i]); 39 | if (hit) 40 | htable_del (ht, hash_string (keys [i]), hit); 41 | else 42 | htable_add (ht, hash_string (keys [i]), keys [i]); 43 | } 44 | 45 | count = htable_count (ht); 46 | 47 | htable_clear (ht); 48 | free (ht); 49 | 50 | return count; 51 | } 52 | -------------------------------------------------------------------------------- /src/ccan/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * R. Carbone on Sun Jul 24 06:18:52 CEST 2016 3 | * 4 | */ 5 | 6 | #include 7 | 8 | 9 | /* Mandatory define (in order to compile htable.c) */ 10 | #if defined(__GNUC__) 11 | #define COLD __attribute__((__cold__)) 12 | #endif 13 | 14 | /* Optional as found in original compiler.h but not needed to compile htable.c */ 15 | #if defined(OPTIONAL) 16 | 17 | #define NORETURN __attribute__((__noreturn__)) 18 | #define PRINTF_FMT(nfmt, narg) __attribute__((format(__printf__, nfmt, narg))) 19 | #define CONST_FUNCTION __attribute__((__const__)) 20 | #define PURE_FUNCTION __attribute__((__pure__)) 21 | #define UNNEEDED __attribute__((__unused__)) 22 | #define NEEDED __attribute__((__used__)) 23 | #define UNUSED __attribute__((__unused__)) 24 | #define IS_COMPILE_CONSTANT(expr) __builtin_constant_p(expr) 25 | #define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) 26 | 27 | #endif /* OPTIONAL */ 28 | 29 | 30 | /* Mandatory in order to compile hash.c */ 31 | #if __BYTE_ORDER == __LITTLE_ENDIAN 32 | #define HAVE_LITTLE_ENDIAN 1 33 | 34 | #elif __BYTE_ORDER == __BIG_ENDIAN 35 | #define HAVE_BIG_ENDIAN 1 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/ccan/run-ccan-htable.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "htable.h" 7 | #include "hash.h" 8 | 9 | 10 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 11 | 12 | /* Hash is simply key itself */ 13 | static size_t hash_int_fn (const void * key, void * unused) 14 | { 15 | return * (unsigned *) key; 16 | } 17 | 18 | 19 | static bool eq_int_fn (const void * a, void * b) 20 | { 21 | return * (unsigned *) a == * (unsigned *) b; 22 | } 23 | 24 | 25 | static size_t hash_str_fn (const void * key, void * unused) 26 | { 27 | return hash_string (key); 28 | } 29 | 30 | 31 | static bool eq_str_fn (const void * a, void * b) 32 | { 33 | return ! strcmp (a, b); 34 | } 35 | 36 | 37 | static unsigned htable_count (struct htable * ht) 38 | { 39 | return ht -> elems; 40 | } 41 | 42 | 43 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 44 | 45 | #include "ccan-udb.c" 46 | #include "ccan-grow.c" 47 | 48 | 49 | int main (int argc, char * argv []) 50 | { 51 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 52 | } 53 | -------------------------------------------------------------------------------- /src/cfu/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = cfuhash.c 3 | LIB = lib-kbench-cfu.a 4 | MAINSRCS = run-cfu.c 5 | 6 | DEFINES = -DHAVE_STRNCASECMP -DHAVE_STRINGS_H 7 | 8 | include ../../etc/Make.rules 9 | -------------------------------------------------------------------------------- /src/cfu/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name libcfu 6 | Module cfu 7 | Author Don Owens 8 | Description Libcfu is a library of thread-safe functions and data structures 9 | Download http://sourceforge.net/projects/libcfu 10 | Date 2005 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | The following sources files were copied from a github updated version by Matthew Brush available at: 16 | http://github.com/codebrainz/libcfu 17 | 18 | - cfu.h 19 | - cfuhash.h 20 | - cfuhash.c 21 | 22 | 23 | The following modifications were needed to compile the files as a standalone module: 24 | - cfuhash.c => added defines to include system headers 25 | avoid inclusion of cfustring.h and remove dependencies from cfuhash_bencode_strings() 26 | 27 | Makefile includes some defines needed to compile the sources: 28 | 29 | (eg DEFINES = -DHAVE_STRNCASECMP -DHAVE_STRINGS_H) 30 | -------------------------------------------------------------------------------- /src/cfu/cfu-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | cfuhash_table_t * ht = cfuhash_new (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | cfuhash_put_data (ht, & keys [i], sizeof (keys [i]), & i, sizeof (i), NULL); 10 | 11 | count = cfuhash_num_entries (ht); 12 | 13 | cfuhash_destroy (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | cfuhash_table_t * ht = cfuhash_new (); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | cfuhash_put (ht, keys [i], & i); 27 | 28 | count = cfuhash_num_entries (ht); 29 | 30 | cfuhash_destroy (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/cfu/cfu-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | cfuhash_table_t * ht = cfuhash_new (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (cfuhash_exists_data (ht, & keys [i], sizeof (keys [i]))) 11 | cfuhash_delete_data (ht, & keys [i], sizeof (keys [i])); 12 | else 13 | cfuhash_put_data (ht, & keys [i], sizeof (keys [i]), & i, sizeof (i), NULL); 14 | } 15 | 16 | count = cfuhash_num_entries (ht); 17 | 18 | cfuhash_destroy (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | cfuhash_table_t * ht = cfuhash_new (); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (cfuhash_exists (ht, keys [i])) 33 | cfuhash_delete (ht, keys [i]); 34 | else 35 | cfuhash_put (ht, keys [i], & i); 36 | } 37 | 38 | count = cfuhash_num_entries (ht); 39 | 40 | cfuhash_destroy (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/cfu/run-cfu.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "cfuhash.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #include "cfu-udb.c" 11 | #include "cfu-grow.c" 12 | 13 | 14 | int main (int argc, char * argv []) 15 | { 16 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 17 | } 18 | -------------------------------------------------------------------------------- /src/eastl/EASTL/internal/allocator_traits_fwd_decls.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Electronic Arts Inc. All rights reserved. 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | 6 | #ifndef EASTL_INTERNAL_ALLOCATOR_TRAITS_H 7 | #define EASTL_INTERNAL_ALLOCATOR_TRAITS_H 8 | 9 | 10 | #include 11 | #if defined(EA_PRAGMA_ONCE_SUPPORTED) 12 | #pragma once 13 | #endif 14 | 15 | #include 16 | #include 17 | 18 | namespace eastl 19 | { 20 | template 21 | struct allocator_traits; 22 | 23 | } // namespace eastl 24 | 25 | #endif // Header include guard 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/eastl/EASTL/internal/tuple_fwd_decls.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) Electronic Arts Inc. All rights reserved. 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #ifndef EASTL_TUPLE_FWD_DECLS_H 6 | #define EASTL_TUPLE_FWD_DECLS_H 7 | 8 | #include 9 | 10 | #if EASTL_TUPLE_ENABLED 11 | 12 | namespace eastl 13 | { 14 | 15 | template 16 | class tuple; 17 | 18 | template 19 | class tuple_size; 20 | 21 | template 22 | class tuple_element; 23 | 24 | template 25 | using tuple_element_t = typename tuple_element::type; 26 | } 27 | 28 | #endif // EASTL_VARIADIC_TEMPLATES_ENABLED 29 | 30 | #endif // EASTL_TUPLE_FWD_DECLS_H 31 | -------------------------------------------------------------------------------- /src/eastl/EASTL/internal/type_pod.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcarbone/kbench/4ce1c71a2c44c969130fc892d282f4ccc85a508d/src/eastl/EASTL/internal/type_pod.h -------------------------------------------------------------------------------- /src/eastl/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-ea.cpp 3 | 4 | INCLUDE = -IEASTL 5 | C++FLAGS = -fpermissive 6 | C++FLAGS += -Wno-sign-compare 7 | SYSLIBS += -lstdc++ -lm 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/eastl/eastl-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t; 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 27 | 28 | count = ht -> size (); 29 | 30 | delete ht; 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/eastl/eastl-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/emilib/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-emilib.cpp 3 | 4 | C++FLAGS = -Wno-sign-compare 5 | SYSLIBS += -lstdc++ -lpthread -ldl 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/emilib/grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert ({keys [i], keys [i]}); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t (); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ht -> insert ({keys [i], i}); 27 | 28 | count = ht -> size (); 29 | 30 | delete ht; 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/emilib/run-emilib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | #include "rhash.h" 6 | 7 | /* The implementation */ 8 | #define LOGURU_IMPLEMENTATION 0 9 | #include "hash_map.hpp" 10 | using namespace emilib; 11 | 12 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 13 | 14 | typedef emilib::HashMap hashtable_int_t; 15 | typedef emilib::HashMap hashtable_str_t; 16 | 17 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 18 | 19 | #include "udb.cpp" 20 | #include "grow.cpp" 21 | 22 | 23 | int main (int argc, char * argv []) 24 | { 25 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 26 | } 27 | -------------------------------------------------------------------------------- /src/emilib/udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert ({keys [i], keys [i]}); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t (); 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert ({keys [i], i}); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/gcc-libiberty/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hashtab.c 3 | LIB = lib-kbench-gcc.a 4 | MAINSRCS = run-gcc.c 5 | 6 | DEFINES = -DHAVE_MALLOC_H -DHAVE_STDINT_H -DHAVE_STDLIB_H -DHAVE_STRING_H 7 | 8 | include ../../etc/Make.rules 9 | -------------------------------------------------------------------------------- /src/gcc-libiberty/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name hashtab in libiberty library included in gcc 6 | Module hashtab 7 | Author Vladimir Makarov (vmakarov@cygnus.com) 8 | Description An expandable hash tables datatype 9 | Download http://gcc.gnu.org 10 | Date 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | The following sources files were copied from latest git version: 16 | - ansidecl.h 17 | - hashtab.h 18 | - hashtab.c 19 | 20 | Moreover hashtab.c was locally modified in order to: 21 | 22 | - avoid to call xcalloc and therefore to depend also from additional xmalloc.c and xexit.c source files 23 | - fix a segmentation violation when attempt to delete items not already in the hash table 24 | 25 | Makefile includes some defines needed to compile the sources: 26 | 27 | (eg DEFINES = -DHAVE_MALLOC_H -DHAVE_STDINT_H -DHAVE_STDLIB_H -DHAVE_STRING_H) 28 | -------------------------------------------------------------------------------- /src/gcc-libiberty/gcc-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | htab_t ht = htab_create (0, hash_int_fn, eq_int_fn, NULL); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | void ** elem = htab_find_slot (ht, & keys [i], INSERT); 11 | if (elem) 12 | * elem = (void *) & keys [i]; 13 | } 14 | 15 | count = htab_elements (ht); 16 | 17 | htab_delete (ht); 18 | 19 | return count; 20 | } 21 | 22 | 23 | unsigned grow_str (unsigned n, char ** keys) 24 | { 25 | htab_t ht = htab_create (0, hash_str_fn, eq_str_fn, NULL); 26 | unsigned i; 27 | unsigned count; 28 | 29 | for (i = 0; i < n; i ++) 30 | { 31 | void ** elem = htab_find_slot (ht, keys [i], INSERT); 32 | if (elem) 33 | * elem = (void *) keys [i]; 34 | } 35 | 36 | count = htab_elements (ht); 37 | 38 | htab_delete (ht); 39 | 40 | return count; 41 | } 42 | -------------------------------------------------------------------------------- /src/gcc-libiberty/gcc-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | htab_t ht = htab_create (0, hash_int_fn, eq_int_fn, NULL); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (htab_find (ht, & keys [i])) 11 | htab_remove_elt (ht, (void *) & keys [i]); 12 | else 13 | { 14 | void ** elem = htab_find_slot (ht, & keys [i], INSERT); 15 | if (elem) 16 | * elem = (void *) & keys [i]; 17 | } 18 | } 19 | 20 | count = htab_elements (ht); 21 | 22 | htab_delete (ht); 23 | 24 | return count; 25 | } 26 | 27 | 28 | unsigned udb_str (unsigned n, char ** keys) 29 | { 30 | htab_t ht = htab_create (0, hash_str_fn, eq_str_fn, NULL); 31 | unsigned i; 32 | unsigned count; 33 | 34 | for (i = 0; i < n; i ++) 35 | { 36 | if (htab_find (ht, keys [i])) 37 | htab_remove_elt (ht, keys [i]); 38 | else 39 | { 40 | void ** elem = htab_find_slot (ht, keys [i], INSERT); 41 | if (elem) 42 | * elem = (void *) keys [i]; 43 | } 44 | } 45 | 46 | count = htab_elements (ht); 47 | 48 | htab_delete (ht); 49 | 50 | return count; 51 | } 52 | -------------------------------------------------------------------------------- /src/gcc-libiberty/run-gcc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | 6 | /* The implementation */ 7 | #include "hashtab.h" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | #include "rhash.h" 12 | 13 | static hashval_t hash_int_fn (const void * key) 14 | { 15 | return java_hash (* (unsigned *) key); 16 | } 17 | 18 | 19 | static int eq_int_fn (const void * key1, const void * key2) 20 | { 21 | return * (unsigned *) key1 == * (unsigned *) key2; 22 | } 23 | 24 | 25 | static hashval_t hash_str_fn (const void * key) 26 | { 27 | return python_hash (key); 28 | } 29 | 30 | 31 | static int eq_str_fn (const void * key1, const void * key2) 32 | { 33 | return ! strcmp (key1, key2); 34 | } 35 | 36 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 37 | 38 | #include "gcc-udb.c" 39 | #include "gcc-grow.c" 40 | 41 | 42 | int main (int argc, char * argv []) 43 | { 44 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 45 | } 46 | -------------------------------------------------------------------------------- /src/generic-c-hashmap/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-gc-hashmap.c 3 | 4 | CFLAGS += -std=c99 # no more required with gcc 5.4.0 5 | 6 | include ../../etc/Make.rules 7 | -------------------------------------------------------------------------------- /src/generic-c-hashmap/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name generic-c-hashmap 6 | Module gchashmap 7 | Author Rene' Kijewski (rene.kijewski@fu-berlin.de) 8 | Description generic-c-hashmap should be the easiest way to use hash map for C 9 | Download http://github.com/Kijewski/generic-c-hashmap 10 | Date 2012 11 | Language C macro 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from latest git version: 17 | 18 | - hashmap.h 19 | -------------------------------------------------------------------------------- /src/generic-c-hashmap/gc-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t * objs = calloc (n, sizeof (obj_t)); 5 | gch_int_t * ht = calloc (1, sizeof (* ht)); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | objs [i] . ukey = keys [i]; 12 | objs [i] . uval = i; 13 | } 14 | 15 | for (i = 0; i < n; i ++) 16 | { 17 | obj_t * obj = & objs [i]; 18 | gch_int_Put (ht, & obj, HMDR_STACK); 19 | } 20 | 21 | count = ht -> size; 22 | 23 | gch_int_Destroy (ht); 24 | free (ht); 25 | free (objs); 26 | 27 | return count; 28 | } 29 | 30 | 31 | unsigned grow_str (unsigned n, char ** keys) 32 | { 33 | obj_t * objs = calloc (n, sizeof (obj_t)); 34 | gch_str_t * ht = calloc (1, sizeof (* ht)); 35 | unsigned i; 36 | unsigned count; 37 | 38 | for (i = 0; i < n; i ++) 39 | { 40 | strcpy (objs [i] . skey, keys [i]); 41 | objs [i] . uval = i; 42 | } 43 | 44 | for (i = 0; i < n; i ++) 45 | { 46 | obj_t * obj = & objs [i]; 47 | gch_str_Put (ht, & obj, HMDR_STACK); 48 | } 49 | 50 | count = ht -> size; 51 | 52 | gch_str_Destroy (ht); 53 | free (ht); 54 | free (objs); 55 | 56 | return count; 57 | } 58 | -------------------------------------------------------------------------------- /src/ghthash/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hash_table.c 3 | SRCS += hash_functions.c 4 | LIB = lib-kbench-ght.a 5 | MAINSRCS = run-ght.c 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/ghthash/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name libghthash 6 | Module ght 7 | Author Simon Kagstrom (ska@bth.se) 8 | Description The Generic Hash Table (GHT) 9 | Download http://github.com/SimonKagstrom/libghthash 10 | Date 2002, 2005 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | 18 | - ght_hash_table.h 19 | - hash_table.c 20 | - hash_functions.c -------------------------------------------------------------------------------- /src/ghthash/ght-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | ght_hash_table_t * ht = ght_create (n); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ght_insert (ht, (void *) & keys [i], sizeof (keys [i]), & keys [i]); 10 | 11 | count = ght_count (ht); 12 | 13 | ght_finalize (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | ght_hash_table_t * ht = ght_create (n); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ght_insert (ht, (void *) keys [i], strlen (keys [i]), keys [i]); 27 | 28 | count = ght_count (ht); 29 | 30 | ght_finalize (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/ghthash/ght-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | ght_hash_table_t * ht = ght_create (n); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (ght_get (ht, sizeof (keys [i]), & keys [i])) 11 | ght_remove (ht, sizeof (keys [i]), & keys [i]); 12 | else 13 | ght_insert (ht, (void *) & keys [i], sizeof (keys [i]), & keys [i]); 14 | } 15 | 16 | count = ght_count (ht); 17 | 18 | ght_finalize (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | ght_hash_table_t * ht = ght_create (n); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (ght_get (ht, strlen (keys [i]), keys [i])) 33 | ght_remove (ht, strlen (keys [i]), keys [i]); 34 | else 35 | ght_insert (ht, (void *) keys [i], strlen (keys [i]), keys [i]); 36 | } 37 | 38 | count = ght_count (ht); 39 | 40 | ght_finalize (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/ghthash/run-ght.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "ght_hash_table.h" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | static unsigned ght_count (ght_hash_table_t * ht) 11 | { 12 | return ht -> i_items; 13 | } 14 | 15 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 16 | 17 | #include "ght-udb.c" 18 | #include "ght-grow.c" 19 | 20 | 21 | int main (int argc, char * argv []) 22 | { 23 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 24 | } 25 | -------------------------------------------------------------------------------- /src/google-c/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = libchash.c 3 | LIB = lib-kbench-google.a 4 | MAINSRCS = run-dense.c 5 | MAINSRCS += run-sparse.c 6 | 7 | WFLAGS = -Wno-parentheses 8 | WFLAGS += -Wno-unused-function 9 | WFLAGS += -Wno-address 10 | WFLAGS += -Wno-strict-aliasing 11 | 12 | include ../../etc/Make.rules 13 | -------------------------------------------------------------------------------- /src/google-c/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name c-google 6 | Module Dense/Sparse Hash Table 7 | Author Craig Silverstein 8 | Description in-memory hash tables 9 | Download http://github.com/sparsehash/sparsehash 10 | Date 2005, 2010 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | - libchash.h 18 | - libchash.c 19 | 20 | Both have been subject to modifications in order to compile the files as a standalone module 21 | to avoid inclusion of header 22 | -------------------------------------------------------------------------------- /src/google-c/google-dense-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | struct HashTable * ht = AllocateHashTable (sizeof (unsigned), DONTCOPY); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (HashFind (ht, keys [i])) 11 | HashDelete (ht, keys [i]); 12 | else 13 | HashInsert (ht, keys [i], keys [i]); 14 | } 15 | 16 | count = HashCount (ht); 17 | 18 | FreeHashTable (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned grow_str (unsigned n, char ** keys) 25 | { 26 | struct HashTable * ht = AllocateHashTable (0, DONTCOPY); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (HashFind (ht, (ulong) keys [i])) 33 | HashDelete (ht, (ulong) keys [i]); 34 | else 35 | HashInsert (ht, (ulong) keys [i], i); 36 | } 37 | 38 | count = HashCount (ht); 39 | 40 | FreeHashTable (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/google-c/google-dense-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | struct HashTable * ht = AllocateHashTable (sizeof (unsigned), DONTCOPY); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (HashFind (ht, keys [i])) 11 | HashDelete (ht, keys [i]); 12 | else 13 | HashInsert (ht, keys [i], keys [i]); 14 | } 15 | 16 | count = HashCount (ht); 17 | 18 | FreeHashTable (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | struct HashTable * ht = AllocateHashTable (0, DONTCOPY); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (HashFind (ht, (ulong) keys [i])) 33 | HashDelete (ht, (ulong) keys [i]); 34 | else 35 | HashInsert (ht, (ulong) keys [i], i); 36 | } 37 | 38 | count = HashCount (ht); 39 | 40 | FreeHashTable (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/google-c/google-sparse-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | struct HashTable * ht = AllocateHashTable (sizeof (unsigned), DONTCOPY); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | HashInsert (ht, keys [i], keys [i]); 10 | 11 | count = HashCount (ht); 12 | 13 | FreeHashTable (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | struct HashTable * ht = AllocateHashTable (0, DONTCOPY); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | HashInsert (ht, (ulong) keys [i], i); 27 | 28 | count = HashCount (ht); 29 | 30 | FreeHashTable (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/google-c/google-sparse-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | struct HashTable * ht = AllocateHashTable (sizeof (unsigned), DONTCOPY); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (HashFind (ht, keys [i])) 11 | HashDelete (ht, keys [i]); 12 | else 13 | HashInsert (ht, keys [i], keys [i]); 14 | } 15 | 16 | count = HashCount (ht); 17 | 18 | FreeHashTable (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | struct HashTable * ht = AllocateHashTable (0, DONTCOPY); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (HashFind (ht, (ulong) keys [i])) 33 | HashDelete (ht, (ulong) keys [i]); 34 | else 35 | HashInsert (ht, (ulong) keys [i], i); 36 | } 37 | 38 | count = HashCount (ht); 39 | 40 | FreeHashTable (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/google-c/run-dense.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #define Table(x) Dense##x /* Google Dense tables */ 7 | #include "libchash.h" 8 | 9 | 10 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 11 | 12 | #define DONTCOPY 0 13 | 14 | static unsigned HashCount (struct HashTable * ht) 15 | { 16 | return ht -> cItems; 17 | } 18 | 19 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 20 | 21 | #include "google-dense-udb.c" 22 | #include "google-dense-grow.c" 23 | 24 | 25 | int main (int argc, char * argv []) 26 | { 27 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 28 | } 29 | -------------------------------------------------------------------------------- /src/google-c/run-sparse.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #define Table(x) Sparse##x /* Google Sparse tables */ 7 | #include "libchash.h" 8 | 9 | 10 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 11 | 12 | #define DONTCOPY 0 13 | 14 | static unsigned HashCount (struct HashTable * ht) 15 | { 16 | return ht -> cItems; 17 | } 18 | 19 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 20 | 21 | #include "google-sparse-udb.c" 22 | #include "google-sparse-grow.c" 23 | 24 | 25 | int main (int argc, char * argv []) 26 | { 27 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 28 | } 29 | -------------------------------------------------------------------------------- /src/hashit/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hashit.c 3 | SRCS += hfunctions.c 4 | LIB = lib-kbench-hashit.a 5 | MAINSRCS = run-open.c 6 | MAINSRCS += run-overflow.c 7 | MAINSRCS += run-chain.c 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/hashit/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name hashit 6 | Module chaining - open addressing - overflow hash table 7 | Author David Gomez (david@pleyades.net) 8 | Description Hashit - Another generic hash library 9 | Download http://freecode.com/projects/hashit 10 | Date 2004-2010 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from a git clone available at: 17 | http://github.com/neurodrone/hashit 18 | 19 | - hashit.h 20 | - hashit.c 21 | - hfunctions.h 22 | - hfunctions.c 23 | -------------------------------------------------------------------------------- /src/hashit/hashit-chain-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hash_t ht = hashit_create (n, sizeof (unsigned), NULL, cmp_int_fn, H_HT_TYPE); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | hashit_insert (ht, (unsigned *) & keys [i], & i); 10 | 11 | count = hashit_size (ht); 12 | 13 | hashit_destroy (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hash_t ht = hashit_create (n, 0, NULL, cmp_str_fn, H_HT_TYPE); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | hashit_insert (ht, keys [i], & i); 27 | 28 | count = hashit_size (ht); 29 | 30 | hashit_destroy (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/hashit/hashit-chain-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hash_t ht = hashit_create (n, sizeof (unsigned), NULL, cmp_int_fn, H_HT_TYPE); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (hashit_lookup (ht, (unsigned *) & keys [i])) 11 | hashit_delete (ht, (unsigned *) & keys [i]); 12 | else 13 | hashit_insert (ht, (unsigned *) & keys [i], & i); 14 | } 15 | 16 | count = hashit_size (ht); 17 | 18 | hashit_destroy (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | hash_t ht = hashit_create (n, 0, NULL, cmp_str_fn, H_HT_TYPE); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (hashit_lookup (ht, keys [i])) 33 | hashit_delete (ht, keys [i]); 34 | else 35 | hashit_insert (ht, keys [i], & i); 36 | } 37 | 38 | count = hashit_size (ht); 39 | 40 | hashit_destroy (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/hashit/hashit-open-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hash_t ht = hashit_create (n, sizeof (unsigned), NULL, cmp_int_fn, H_HT_TYPE); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | hashit_insert (ht, & keys [i], & i); 10 | 11 | count = hashit_size (ht); 12 | 13 | hashit_destroy (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hash_t ht = hashit_create (n, 0, NULL, cmp_str_fn, H_HT_TYPE); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | hashit_insert (ht, keys [i], & i); 27 | 28 | count = hashit_size (ht); 29 | 30 | hashit_destroy (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/hashit/hashit-open-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hash_t ht = hashit_create (n, sizeof (unsigned), NULL, cmp_int_fn, H_HT_TYPE); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (hashit_lookup (ht, (unsigned *) & keys [i])) 11 | hashit_delete (ht, (unsigned *) & keys [i]); 12 | else 13 | hashit_insert (ht, (unsigned *) & keys [i], & i); 14 | } 15 | 16 | count = hashit_size (ht); 17 | 18 | hashit_destroy (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | hash_t ht = hashit_create (n, 0, NULL, cmp_str_fn, H_HT_TYPE); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (hashit_lookup (ht, keys [i])) 33 | hashit_delete (ht, keys [i]); 34 | else 35 | hashit_insert (ht, keys [i], & i); 36 | } 37 | 38 | count = hashit_size (ht); 39 | 40 | hashit_destroy (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/hashit/hashit-overflow-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hash_t ht = hashit_create (n, sizeof (unsigned), NULL, cmp_int_fn, H_HT_TYPE); 5 | 6 | unsigned count; 7 | unsigned i; 8 | 9 | for (i = 0; i < n; i ++) 10 | hashit_insert (ht, (unsigned *) & keys [i], & i); 11 | 12 | count = hashit_size (ht); 13 | 14 | hashit_destroy (ht); 15 | 16 | return count; 17 | } 18 | 19 | 20 | unsigned grow_str (unsigned n, char ** keys) 21 | { 22 | hash_t ht = hashit_create (n, 0, NULL, cmp_str_fn, H_HT_TYPE); 23 | 24 | unsigned count; 25 | unsigned i; 26 | 27 | for (i = 0; i < n; i ++) 28 | hashit_insert (ht, keys [i], & i); 29 | 30 | count = hashit_size (ht); 31 | 32 | hashit_destroy (ht); 33 | 34 | return count; 35 | } 36 | -------------------------------------------------------------------------------- /src/hashit/hashit-overflow-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hash_t ht = hashit_create (n, sizeof (unsigned), NULL, cmp_int_fn, H_HT_TYPE); 5 | 6 | unsigned count; 7 | unsigned i; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | if (hashit_lookup (ht, (unsigned *) & keys [i])) 12 | hashit_delete (ht, (unsigned *) & keys [i]); 13 | else 14 | hashit_insert (ht, (unsigned *) & keys [i], & i); 15 | } 16 | 17 | count = hashit_size (ht); 18 | 19 | hashit_destroy (ht); 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hash_t ht = hashit_create (n, 0, NULL, cmp_str_fn, H_HT_TYPE); 28 | 29 | unsigned count; 30 | unsigned i; 31 | 32 | for (i = 0; i < n; i ++) 33 | { 34 | if (hashit_lookup (ht, keys [i])) 35 | hashit_delete (ht, keys [i]); 36 | else 37 | hashit_insert (ht, keys [i], & i); 38 | } 39 | 40 | count = hashit_size (ht); 41 | 42 | hashit_destroy (ht); 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/hashit/hashit.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcarbone/kbench/4ce1c71a2c44c969130fc892d282f4ccc85a508d/src/hashit/hashit.c -------------------------------------------------------------------------------- /src/hashit/hashit.h: -------------------------------------------------------------------------------- 1 | #ifndef __HASHIT__ 2 | #define __HASHIT__ 3 | 4 | #define CHAIN_H 0U 5 | #define OADDRESS_H 1U 6 | #define OVERFLOW_H 2U 7 | 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | struct shash_t; 17 | typedef struct shash_t *hash_t; 18 | 19 | hash_t hashit_create(uint32_t, size_t, uint32_t(*)(), int(*)(void *, void *), unsigned int); 20 | int hashit_insert(hash_t, void *, void *); 21 | int hashit_delete(hash_t, void *); 22 | int hashit_replace(hash_t, void *, void *); 23 | void *hashit_lookup(hash_t, void *); 24 | int hashit_destroy(hash_t); 25 | /* Accesors */ 26 | void **hashit_getkeys(hash_t); 27 | void **hashit_getvalues(hash_t); 28 | size_t hashit_tablesize(hash_t); 29 | size_t hashit_size(hash_t); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /src/hashit/hfunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef __HFUNCTIONS__ 2 | #define __HFUNCTIONS__ 3 | 4 | #define BOB_HASH bob_hash 5 | #define ONEAT_HASH oneatatime_hash 6 | 7 | uint32_t bob_hash(unsigned char *, unsigned long); 8 | uint32_t oneatatime_hash(unsigned char *, size_t); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/hashit/run-chain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "hashit.h" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #define H_HT_TYPE CHAIN_H 11 | 12 | static int cmp_int_fn (void * a, void * b) 13 | { 14 | return * (unsigned *) a - * (unsigned *) b; 15 | } 16 | 17 | 18 | static int cmp_str_fn (void * a, void * b) 19 | { 20 | return strcmp (a, b); 21 | } 22 | 23 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 24 | 25 | #include "hashit-chain-udb.c" 26 | #include "hashit-chain-grow.c" 27 | 28 | 29 | int main (int argc, char * argv []) 30 | { 31 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 32 | } 33 | -------------------------------------------------------------------------------- /src/hashit/run-open.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "hashit.h" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #define H_HT_TYPE OADDRESS_H 11 | 12 | static int cmp_int_fn (void * a, void * b) 13 | { 14 | return * (unsigned *) a - * (unsigned *) b; 15 | } 16 | 17 | 18 | static int cmp_str_fn (void * a, void * b) 19 | { 20 | return strcmp (a, b); 21 | } 22 | 23 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 24 | 25 | #include "hashit-open-udb.c" 26 | #include "hashit-open-grow.c" 27 | 28 | 29 | int main (int argc, char * argv []) 30 | { 31 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 32 | } 33 | -------------------------------------------------------------------------------- /src/hashit/run-overflow.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "hashit.h" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #define H_HT_TYPE OVERFLOW_H 11 | 12 | static int cmp_int_fn (void * a, void * b) 13 | { 14 | return a && b ? * (unsigned *) a - * (unsigned *) b : 1; 15 | } 16 | 17 | 18 | static int cmp_str_fn (void * a, void * b) 19 | { 20 | return a && b ? strcmp (a, b) : 1; 21 | } 22 | 23 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 24 | 25 | #include "hashit-overflow-udb.c" 26 | #include "hashit-overflow-grow.c" 27 | 28 | 29 | int main (int argc, char * argv []) 30 | { 31 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 32 | } 33 | -------------------------------------------------------------------------------- /src/hhash/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hhash.c 3 | LIB = lib-kbench-hhash.a 4 | MAINSRCS = run-hhash.c 5 | 6 | CFLAGS += -std=c99 # no more required with gcc 5.4.0 7 | 8 | include ../../etc/Make.rules 9 | -------------------------------------------------------------------------------- /src/hhash/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name hhash 6 | Module Hopscotch Hash Table 7 | Author Jani Lahtinen (jani.lahtinen8@gmail.com) 8 | Description Hopscotch Hash Table 9 | Download http://github.com/coriolanus/libhhash 10 | Date 2010 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | - hhash.h 18 | - hhash.c 19 | - mach.c 20 | -------------------------------------------------------------------------------- /src/hhash/hhash-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | /* Warning: 0 cannot be used as value */ 5 | HHash * ht = hhashnew (n); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | if (hhashget (ht, keys [i], 0)) 12 | hhashdel (ht, keys [i], 0); 13 | else 14 | hhashput (ht, keys [i], keys [i]); 15 | } 16 | 17 | count = hhashcount (ht); 18 | 19 | hhashfree (ht); 20 | 21 | return count; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/hhash/hhash.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBHHASH_H 2 | #define LIBHHASH_H 3 | 4 | typedef unsigned long ulong; 5 | typedef struct HHash HHash; 6 | 7 | struct HHash { 8 | ulong k, m, n; 9 | ulong *H; 10 | ulong *V; 11 | }; 12 | 13 | #define hhashget(hhash, x, i) ((hhash)->V[((x) + (i)) % (hhash)->n]) 14 | 15 | HHash *hhashnew(ulong); 16 | void hhashfree(HHash *); 17 | int hhashput(HHash *, ulong, ulong); 18 | void hhashdel(HHash *, ulong, ulong); 19 | int hhashsucc(HHash *, ulong, ulong); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/hhash/hhmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hhash.h" 3 | #include "hhset.h" 4 | #include "hhmap.h" 5 | 6 | #define HALF (8 * sizeof(uint)) 7 | 8 | static ulong id(ulong x) { return (uint)x; } 9 | 10 | static int neq(ulong x, ulong y) { return (uint)x != (uint)y; } 11 | 12 | HHSet *hhmapnew(ulong n, ulong (*hash)(ulong), int (*cmp)(ulong, ulong)) { 13 | HHSet *S = malloc(sizeof(HHSet)); 14 | S->T = hhashnew(n); 15 | S->hash = (hash != NULL) ? hash : id; 16 | S->cmp = (cmp != NULL) ? cmp : neq; 17 | return S; 18 | } 19 | 20 | int hhmapput(HHSet *S, uint k, uint v) { 21 | if (v == 0) return 0; 22 | ulong x = (((ulong)v) << HALF) | k; 23 | return hhsetput(S, x); 24 | } 25 | 26 | uint hhmapget(HHSet *S, uint k) { return (uint)(hhsetget(S, k) >> HALF); } 27 | 28 | uint hhmapdel(HHSet *S, uint k) { return (uint)(hhsetdel(S, k) >> HALF); } 29 | -------------------------------------------------------------------------------- /src/hhash/hhmap.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBHHMAP_H 2 | #define LIBHHMAP_H 3 | 4 | typedef unsigned int uint; 5 | 6 | HHSet *hhmapnew(ulong n, ulong (*)(ulong), int (*)(ulong, ulong)); 7 | int hhmapput(HHSet *, uint, uint); 8 | uint hhmapget(HHSet *, uint); 9 | uint hhmapdel(HHSet *, uint); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/hhash/mach.c: -------------------------------------------------------------------------------- 1 | #define WORD (8 * sizeof(ulong)) 2 | 3 | #define clz(x) __builtin_clzl(x) 4 | 5 | #define fls(x) (WORD - clz(x)) 6 | 7 | #define ffs(x) (__builtin_ctzl(x)) 8 | 9 | #define get(x, i) ((x) & (1L << (i))) 10 | 11 | #define set(x, i) (x = (x) | (1L << (i))) 12 | 13 | #define unset(x, i) (x = (x) & ~(1L << (i))) 14 | -------------------------------------------------------------------------------- /src/hhash/run-hhash.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "hhash.h" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | static unsigned hhashcount (HHash * ht) 11 | { 12 | return ht -> m; 13 | } 14 | 15 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 16 | 17 | #include "hhash-udb.c" 18 | 19 | 20 | int main (int argc, char * argv []) 21 | { 22 | return udb_benchmark (argc, argv, udb_int, NULL, NULL, NULL); 23 | } 24 | -------------------------------------------------------------------------------- /src/htable/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-htable.c 3 | 4 | WFLAGS = -Wno-pointer-sign 5 | WFLAGS += -Wno-unused-function 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/htable/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name htable 6 | Module htable 7 | Author Kulesh Shanmugasundaram (kulesh@isis.poly.edu) 8 | Description A type oblivious hash table in C using Linux Kernel list implementation 9 | Download http://isis.poly.edu/kulesh/stuff/src/hashtable.tgz 10 | Date 2008 11 | Language C header 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from Benchmark of Dictionary Structures 17 | by Heng Li available at http://lh3lh3.users.sourceforge.net/download/udb-latest.tar.bz2 18 | 19 | - htable.h 20 | - list.h 21 | 22 | 23 | The following no-warning flags were defined in the Makefile: 24 | WFLAGS = -Wno-pointer-sign 25 | WFLAGS += -Wno-unused-function 26 | 27 | 28 | A more recent version of the software can be downloaded from 29 | http://isis.poly.edu/kulesh/stuff/src/hashtable.tgz 30 | -------------------------------------------------------------------------------- /src/htable/run-htable.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #define inline 5 | #include "htable.h" 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | #define INITIAL_SIZE 127 10 | 11 | typedef struct 12 | { 13 | unsigned uval; 14 | char sval [16]; 15 | 16 | struct hash_entry _reserved_; /* field required to make the object hash-able */ 17 | } item_t; 18 | 19 | 20 | /* Compare two integer values */ 21 | static int cmp_int (const void * a, const void * b, size_t len) 22 | { 23 | return * (unsigned *) a - * (unsigned *) b; 24 | } 25 | 26 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 27 | 28 | #include "htable-udb.c" 29 | #include "htable-grow.c" 30 | 31 | 32 | int main (int argc, char * argv []) 33 | { 34 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 35 | } 36 | -------------------------------------------------------------------------------- /src/judy-template/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = judy.c 3 | LIB = lib-kbench-judy.a 4 | C++MAINSRCS = run-jat.cpp 5 | 6 | CFLAGS += -Wno-parentheses -Wno-unused-but-set-variable -Wno-maybe-uninitialized 7 | C++FLAGS += -Wno-sign-compare 8 | C++FLAGS += -fpermissive 9 | SYSLIBS += -lstdc++ 10 | 11 | include ../../etc/Make.rules 12 | -------------------------------------------------------------------------------- /src/judy-template/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Sep 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name judyarray++ 6 | Module C++ Templates for Judy Array 7 | Author Mark Pictor (mpictor@gmail.com) 8 | Description C++ template wrappers for Judy Array (use of Karl Malbrain's implementation) 9 | Download http://github.com/mpictor/judy-template 10 | Date 2013, 2015 11 | Language C++ templates 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | - judyLArray.h 18 | - judyLArray.h 19 | - judy.h 20 | - judy.c 21 | 22 | I have been a small modification to judyLArray.h in order to change the interface to removeEntry() method 23 | -------------------------------------------------------------------------------- /src/judyarray/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = judy64nb.c 3 | LIB = lib-kbench-ja.a 4 | MAINSRCS = run-ja.c 5 | 6 | CFLAGS += -Wno-parentheses -Wno-unused-but-set-variable 7 | 8 | include ../../etc/Make.rules 9 | -------------------------------------------------------------------------------- /src/judyarray/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name apr 6 | Module hashtable 7 | Author Apache Software Foundation (ASF) 8 | Description Apache Portable Runtime Library 9 | Download http://apache.org 10 | Date 2011, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest version available at: 17 | http://apache.panu.it/apr/apr-1.5.2.tar.gz 18 | 19 | - apr_hash.h 20 | - apr_hash.c 21 | 22 | Both have been subject to modifications in order to compile the files as a standalone module. 23 | 24 | Moreover I fixed 2 memory leaks: 25 | ! defined function apr_hash_done() to free ht->array and ht pointer itself 26 | ! in apr_hash_set() the entry just deleted pointed to by the variable 'old' was not freed 27 | -------------------------------------------------------------------------------- /src/khash/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-khash.c 3 | 4 | include ../../etc/Make.rules 5 | -------------------------------------------------------------------------------- /src/khash/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name klib 6 | Module khash 7 | Author Attractive Chaos (attractor@live.co.uk) - Heng Li (lh3@me.com) 8 | Description Generic hash table based on double hashing 9 | Download http://github.com/attractivechaos/klib 10 | Date 2008, 2009, 2011 11 | Language C macro 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from latest git version without modifications: 17 | - khash.h 18 | -------------------------------------------------------------------------------- /src/khash/khash-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | khash_t(uht_t) * ht = kh_init (uht_t); 5 | unsigned i; 6 | int ret; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | khiter_t hit = kh_put (uht_t, ht, keys [i], & ret); 12 | kh_value (ht, hit) = i + 1; 13 | } 14 | 15 | count = kh_size (ht); 16 | 17 | kh_destroy (uht_t, ht); 18 | 19 | return count; 20 | } 21 | 22 | 23 | unsigned grow_str (unsigned n, char ** keys) 24 | { 25 | khash_t(sht_t) * ht = kh_init (sht_t); 26 | unsigned i; 27 | int ret; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | khiter_t hit = kh_put (sht_t, ht, keys [i], & ret); 33 | kh_value (ht, hit) = i + 1; 34 | } 35 | 36 | count = kh_size (ht); 37 | 38 | kh_destroy (sht_t, ht); 39 | 40 | return count; 41 | } 42 | -------------------------------------------------------------------------------- /src/khash/khash-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | khash_t(uht_t) * ht = kh_init (uht_t); 5 | unsigned i; 6 | int ret; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | khiter_t hit = kh_get (uht_t, ht, keys [i]); 12 | if (hit != kh_end (ht)) 13 | kh_del (uht_t, ht, hit); 14 | else 15 | { 16 | kh_put (uht_t, ht, keys [i], & ret); 17 | kh_value (ht, hit) = i + 1; 18 | } 19 | } 20 | 21 | count = kh_size (ht); 22 | 23 | kh_destroy (uht_t, ht); 24 | 25 | return count; 26 | } 27 | 28 | 29 | unsigned udb_str (unsigned n, char ** keys) 30 | { 31 | khash_t(sht_t) * ht = kh_init (sht_t); 32 | unsigned i; 33 | int ret; 34 | unsigned count; 35 | 36 | for (i = 0; i < n; i ++) 37 | { 38 | khiter_t hit = kh_get (sht_t, ht, keys [i]); 39 | if (hit != kh_end (ht)) 40 | kh_del (sht_t, ht, hit); 41 | else 42 | { 43 | kh_put (sht_t, ht, keys [i], & ret); 44 | kh_value (ht, hit) = i; 45 | } 46 | } 47 | 48 | count = kh_size (ht); 49 | 50 | kh_destroy (sht_t, ht); 51 | 52 | return count; 53 | } 54 | -------------------------------------------------------------------------------- /src/khash/run-khash.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "khash.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | /* Instantiate structs and methods */ 9 | KHASH_MAP_INIT_INT(uht_t, unsigned) 10 | KHASH_MAP_INIT_STR(sht_t, unsigned) 11 | 12 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 13 | 14 | #include "khash-udb.c" 15 | #include "khash-grow.c" 16 | 17 | 18 | int main (int argc, char * argv []) 19 | { 20 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 21 | } 22 | -------------------------------------------------------------------------------- /src/libevent/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-le.c 3 | 4 | include ../../etc/Make.rules 5 | -------------------------------------------------------------------------------- /src/libevent/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name hash table included in the libevent - an event notification library 6 | Module le-ht 7 | Author Niels Provos (provos@umich.edu) 8 | Description Niels Provos's interface to Christopher Clark's hash table implementation 9 | Download http://github.com/libevent/libevent 10 | Date 2005, 2012 11 | Language C macro 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from latest git version at: 17 | http://github.com/libevent/libevent 18 | 19 | - ht-internal.h 20 | 21 | No modification was needed. 22 | -------------------------------------------------------------------------------- /src/libevent/libevent-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t * objs = calloc (n, sizeof (obj_t)); 5 | ht_int_t * ht = calloc (1, sizeof (* ht)); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | objs [i] . ukey = keys [i]; 12 | objs [i] . uval = i; 13 | } 14 | 15 | HT_INIT (evht_int, ht); 16 | 17 | for (i = 0; i < n; i ++) 18 | { 19 | HT_INSERT (evht_int, ht, & objs [i]); 20 | } 21 | 22 | count = HT_SIZE (ht); 23 | 24 | HT_CLEAR (evht_int, ht); 25 | free (ht); 26 | free (objs); 27 | 28 | return count; 29 | } 30 | 31 | 32 | unsigned grow_str (unsigned n, char ** keys) 33 | { 34 | obj_t * objs = calloc (n, sizeof (obj_t)); 35 | ht_str_t * ht = calloc (1, sizeof (* ht)); 36 | unsigned i; 37 | unsigned count; 38 | 39 | for (i = 0; i < n; i ++) 40 | { 41 | strcpy (objs [i] . skey, keys [i]); 42 | objs [i] . uval = i; 43 | } 44 | 45 | for (i = 0; i < n; i ++) 46 | { 47 | HT_INSERT (evht_str, ht, & objs [i]); 48 | } 49 | 50 | count = HT_SIZE (ht); 51 | 52 | HT_CLEAR (evht_str, ht); 53 | free (ht); 54 | free (objs); 55 | 56 | return count; 57 | } 58 | -------------------------------------------------------------------------------- /src/ltable/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = ltable.c 3 | LIB = lib-kbench-ltable.a 4 | MAINSRCS = run-ltable.c 5 | 6 | include ../../etc/Make.rules 7 | -------------------------------------------------------------------------------- /src/ltable/ltable-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | struct ltable * ht = ltable_create (sizeof (unsigned), 0); 5 | unsigned i; 6 | unsigned count; 7 | struct ltable_key key; 8 | unsigned * val; 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | val = ltable_set (ht, ltable_numkey (& key, keys [i])); 13 | * val = keys [i]; 14 | } 15 | 16 | count = ltable_count (ht); 17 | 18 | ltable_release (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned grow_str (unsigned n, char ** keys) 25 | { 26 | struct ltable * ht = ltable_create (sizeof (unsigned), 0); 27 | unsigned i; 28 | unsigned count; 29 | struct ltable_key key; 30 | unsigned * val; 31 | 32 | for (i = 0; i < n; i ++) 33 | { 34 | val = ltable_set (ht, ltable_strkey (& key, keys [i])); 35 | * val = i + 1; 36 | } 37 | 38 | count = ltable_count (ht); 39 | 40 | ltable_release (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/ltable/ltable-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | struct ltable * ht = ltable_create (sizeof (unsigned), 0); 5 | unsigned i; 6 | unsigned count; 7 | struct ltable_key key; 8 | unsigned * val; 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | if (ltable_get (ht, ltable_intkey (& key, keys [i]))) 13 | ltable_del (ht, ltable_intkey (& key, keys [i])); 14 | else 15 | { 16 | val = ltable_set (ht, ltable_intkey (& key, keys [i])); 17 | * val = keys [i]; 18 | } 19 | } 20 | 21 | count = ltable_count (ht); 22 | 23 | ltable_release (ht); 24 | 25 | return count; 26 | } 27 | 28 | 29 | unsigned udb_str (unsigned n, char ** keys) 30 | { 31 | struct ltable * ht = ltable_create (sizeof (unsigned), 0); 32 | unsigned i; 33 | unsigned count; 34 | struct ltable_key key; 35 | unsigned * val; 36 | 37 | for (i = 0; i < n; i ++) 38 | { 39 | if (ltable_get (ht, ltable_strkey (& key, keys [i]))) 40 | ltable_del (ht, ltable_strkey (& key, keys [i])); 41 | else 42 | { 43 | val = ltable_set (ht, ltable_strkey (& key, keys [i])); 44 | * val = i + 1; 45 | } 46 | } 47 | 48 | count = ltable_count (ht); 49 | 50 | ltable_release (ht); 51 | 52 | return count; 53 | } 54 | -------------------------------------------------------------------------------- /src/ltable/run-ltable.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | 6 | /* The implementation */ 7 | #include "ltable.h" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | static unsigned ltable_count (struct ltable * ht) 12 | { 13 | unsigned count = 0; 14 | unsigned i; 15 | int * p; 16 | struct ltable_key kp; 17 | 18 | i = 0; 19 | while ((p = ltable_next (ht, & i, & kp))) 20 | count ++; 21 | return count; 22 | } 23 | 24 | 25 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 26 | 27 | #include "ltable-udb.c" 28 | #include "ltable-grow.c" 29 | 30 | 31 | int main (int argc, char * argv []) 32 | { 33 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 34 | } 35 | -------------------------------------------------------------------------------- /src/lua-table/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = table.c 3 | SRCS += hash.c 4 | LIB = lib-kbench-lua-table.a 5 | MAINSRCS = run-lua-table.c 6 | 7 | CFLAGS += -Wno-int-to-pointer-cast 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/lua-table/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef _H_HASH_H_ 2 | #define _H_HASH_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | typedef enum _htype { 11 | H_NULL, 12 | H_INT8, 13 | H_INT16, 14 | H_INT32, 15 | H_INT64, 16 | H_UINT8, 17 | H_UINT16, 18 | H_UINT32, 19 | H_UINT64, 20 | H_STRING, 21 | H_VOID 22 | } htype_t; 23 | 24 | typedef uint32_t hcode_t; 25 | typedef uint64_t hvalue_t; 26 | typedef hcode_t (*hash_func_t)(const htype_t, const hvalue_t); 27 | typedef int32_t (*hash_equal_func_t)(const htype_t, const hvalue_t, const hvalue_t); 28 | 29 | /** 30 | * The default hashing function. Special functions are used for strings and 31 | * 64-bit integers. For other types, the value itself is used. 32 | */ 33 | extern hcode_t hash_code(const htype_t type, const hvalue_t value); 34 | 35 | /** 36 | * The default hash key equality function. Strings are compared using strcmp, 37 | * other values are compared directly. 38 | */ 39 | extern int32_t hash_equal(const htype_t type, const hvalue_t a, const hvalue_t b); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/lua-table/lua-table-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | table_t * ht = calloc (1, sizeof (* ht)); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | table_set (ht, keys [i], keys [i]); 10 | 11 | count = table_count (ht); 12 | 13 | table_destroy (ht); 14 | free (ht); 15 | 16 | return count; 17 | } 18 | 19 | 20 | unsigned grow_str (unsigned n, char ** keys) 21 | { 22 | table_t * ht = calloc (1, sizeof (* ht)); 23 | unsigned i; 24 | unsigned count; 25 | 26 | for (i = 0; i < n; i ++) 27 | table_set (ht, (hvalue_t) keys [i], i + 1); 28 | 29 | count = table_count (ht); 30 | 31 | table_destroy (ht); 32 | free (ht); 33 | 34 | return count; 35 | } 36 | -------------------------------------------------------------------------------- /src/lua-table/lua-table-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | table_t * ht = calloc (1, sizeof (* ht)); 5 | unsigned i; 6 | unsigned count; 7 | 8 | table_init (ht, H_INT64, NULL, NULL); 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | if (table_contains (ht, keys [i])) 13 | table_delete (ht, keys [i]); 14 | else 15 | table_set (ht, keys [i], keys [i]); 16 | } 17 | 18 | count = table_count (ht); 19 | 20 | table_destroy (ht); 21 | free (ht); 22 | 23 | return count; 24 | } 25 | 26 | 27 | unsigned udb_str (unsigned n, char ** keys) 28 | { 29 | table_t * ht = calloc (1, sizeof (* ht)); 30 | unsigned i; 31 | unsigned count; 32 | 33 | table_init (ht, H_STRING, NULL, NULL); 34 | 35 | for (i = 0; i < n; i ++) 36 | { 37 | if (table_contains (ht, (hvalue_t) keys [i])) 38 | table_delete (ht, (hvalue_t) keys [i]); 39 | else 40 | table_set (ht, (hvalue_t) keys [i], i + 1); 41 | } 42 | 43 | count = table_count (ht); 44 | 45 | table_destroy (ht); 46 | free (ht); 47 | 48 | return count; 49 | } 50 | -------------------------------------------------------------------------------- /src/lua-table/run-lua-table.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | 6 | /* The implementation */ 7 | #include "table.h" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | static int32_t table_count (table_t * ht) 12 | { 13 | unsigned count = 0; 14 | int32_t i = (1 << ht -> nodes_size_log) - 1; 15 | 16 | while (i >= 0) 17 | { 18 | table_node_t * node = & ht -> nodes [i --]; 19 | if (node -> active) 20 | count ++; 21 | } 22 | return count; 23 | } 24 | 25 | 26 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 27 | 28 | #include "lua-table-udb.c" 29 | #include "lua-table-grow.c" 30 | 31 | 32 | int main (int argc, char * argv []) 33 | { 34 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 35 | } 36 | -------------------------------------------------------------------------------- /src/mct/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-mct-closed.cpp 3 | C++MAINSRCS += run-mct-linked.cpp 4 | 5 | INCLUDE = -Imct 6 | C++FLAGS = -Wno-sign-compare 7 | SYSLIBS += -lstdc++ -lm 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/mct/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Sep 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name mct 6 | Module hash table containers 7 | Author Paul Pogonyshev (pogonyshev@gmail.net) 8 | Description Miscellaneous Container Templates 9 | Download https://launchpad.net/libmct 10 | Date 2012, 2013 11 | Language C++ 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | - mct/config.hpp 18 | - mct/hash-map.hpp 19 | - mct/intrusiveness.hpp 20 | 21 | - mct/impl/closed-hash-table.hpp 22 | - mct/impl/optimization.hpp 23 | - mct/impl/utils.hpp 24 | -------------------------------------------------------------------------------- /src/mct/mct-closed-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned grow_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/mct/mct-closed-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/mct/mct-linked-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t; 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 27 | 28 | count = ht -> size (); 29 | 30 | delete ht; 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/mct/mct-linked-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/mct/mct/config.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MCT_CONFIG_HPP 2 | #define MCT_CONFIG_HPP 3 | 4 | // MCT version. 5 | #define MCT_MAJOR_VERSION 1 6 | #define MCT_MINOR_VERSION 6 7 | #define MCT_PATCH_VERSION 2 8 | #define MCT_VERSION_STRING "1.6.2" 9 | 10 | // Library support, including stdlib. 11 | #if !defined (MCT_HASH_HEADER) || !defined (MCT_HASH_NAMESPACE) 12 | # define MCT_HASH_HEADER 13 | # define MCT_HASH_NAMESPACE std 14 | #endif 15 | 16 | #if !defined (MCT_TYPE_TRAITS_HEADER) || !defined (MCT_TYPE_TRAITS_NAMESPACE) 17 | # define MCT_HAVE_TYPE_TRAITS 1 18 | # define MCT_TYPE_TRAITS_HEADER 19 | # define MCT_TYPE_TRAITS_NAMESPACE std 20 | #else 21 | # define MCT_HAVE_TYPE_TRAITS 1 22 | #endif 23 | 24 | // Compiler capabilities. 25 | #if !defined (MCT_CXX0X_SUPPORTED) 26 | # define MCT_CXX0X_SUPPORTED 1 27 | #endif 28 | 29 | #if !defined (MCT_HAVE_LONG_LONG) 30 | # define MCT_HAVE_LONG_LONG 1 31 | #endif 32 | 33 | #endif // Multi-inclusion guard. 34 | 35 | 36 | // Local variables: 37 | // mode: c++ 38 | // c-basic-offset: 2 39 | // indent-tabs-mode: nil 40 | // fill-column: 90 41 | // End: 42 | -------------------------------------------------------------------------------- /src/mct/run-mct-closed.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | 6 | /* The implementation */ 7 | #include "mct/hash-map.hpp" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | typedef mct::closed_hash_map hashtable_int_t; 12 | typedef mct::closed_hash_map hashtable_str_t; 13 | 14 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 15 | 16 | #include "mct-closed-udb.cpp" 17 | #include "mct-closed-grow.cpp" 18 | 19 | 20 | int main (int argc, char * argv []) 21 | { 22 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 23 | } 24 | -------------------------------------------------------------------------------- /src/mct/run-mct-linked.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | 6 | /* The implementation */ 7 | #include "mct/hash-map.hpp" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | typedef mct::linked_hash_map hashtable_int_t; 12 | typedef mct::linked_hash_map hashtable_str_t; 13 | 14 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 15 | 16 | #include "mct-linked-udb.cpp" 17 | #include "mct-linked-grow.cpp" 18 | 19 | 20 | int main (int argc, char * argv []) 21 | { 22 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 23 | } 24 | -------------------------------------------------------------------------------- /src/oddou-hashmap/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-oddou.cpp 3 | 4 | C++FLAGS = -Wno-sign-compare 5 | SYSLIBS += -lstdc++ -lm 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/oddou-hashmap/grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert ({keys [i], keys [i]}); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t; 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ht -> insert ({keys [i], i}); 27 | 28 | count = ht -> size (); 29 | 30 | delete ht; 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/oddou-hashmap/run-oddou.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "benchmark.h" 6 | #include "rhash.h" 7 | 8 | /* The implementation */ 9 | static bool _antiresize_recursion = false; 10 | #include 11 | 12 | using namespace container; 13 | 14 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 15 | 16 | typedef container::hash_map hashtable_int_t; 17 | typedef container::hash_map hashtable_str_t; 18 | 19 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 20 | 21 | #include "udb.cpp" 22 | #include "grow.cpp" 23 | 24 | 25 | int main (int argc, char * argv []) 26 | { 27 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 28 | } 29 | -------------------------------------------------------------------------------- /src/oddou-hashmap/udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert ({keys [i], keys [i]}); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert ({keys [i], i}); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/python/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = hashtable.c 3 | SRCS += pyhash.c 4 | LIB = lib-kbench-python.a 5 | MAINSRCS = run-python.c 6 | 7 | WFLAGS += -Wno-int-to-pointer-cast 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/python/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name python 6 | Module py-ht 7 | Author Don Owens (don@owensnet.com) 8 | Description hash table implementation bundled with Python (based on cfuhash library) 9 | Download http://python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz 10 | Date 2005 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from the Python-3.5.2 distribution: 17 | 18 | - hashtable.h 19 | - hashtable.c 20 | - pyhash.h 21 | - pyhash.c 22 | 23 | 24 | The following modifications were needed to compile the files as a standalone module 25 | (an anti-Python reverse enginering process): 26 | - hashtable.h => define here all the required definitions originally in Python.h 27 | - hashtable.c => avoid inclusion of Python.h and remove dependencies from PyMem_RawMalloc() and PyMem_RawFree() 28 | allow delete of non-existing keys 29 | - pyhash.h => define here all the required definitions originally in Python.h 30 | - pyhash.c => include pyhash.h to avoid inclusion of Python.h 31 | -------------------------------------------------------------------------------- /src/python/python-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | _Py_hashtable_t * ht = _Py_hashtable_new (INT_VAL_SIZE, _Py_hashtable_hash_int, _Py_hashtable_compare_direct); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | _Py_HASHTABLE_SET (ht, (const void *) keys [i], i); 10 | 11 | count = ht -> entries; 12 | 13 | _Py_hashtable_destroy (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | _Py_hashtable_t * ht = _Py_hashtable_new (INT_VAL_SIZE, _Py_hashtable_hash_str, _Py_hashtable_compare_string); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | _Py_HASHTABLE_SET (ht, keys [i], i); 27 | 28 | count = ht -> entries; 29 | 30 | _Py_hashtable_destroy (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/python/python-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | _Py_hashtable_t * ht = _Py_hashtable_new (INT_VAL_SIZE, _Py_hashtable_hash_int, _Py_hashtable_compare_direct); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (_Py_hashtable_get_entry (ht, (const void *) keys [i])) 11 | _Py_hashtable_delete (ht, (const void *) keys [i]); 12 | else 13 | _Py_HASHTABLE_SET (ht, (const void *) keys [i], i); 14 | } 15 | 16 | count = ht -> entries; 17 | 18 | _Py_hashtable_destroy (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | _Py_hashtable_t * ht = _Py_hashtable_new (INT_VAL_SIZE, _Py_hashtable_hash_str, _Py_hashtable_compare_string); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (_Py_hashtable_get_entry (ht, keys [i])) 33 | _Py_hashtable_delete (ht, keys [i]); 34 | else 35 | _Py_HASHTABLE_SET (ht, keys [i], i); 36 | } 37 | 38 | count = ht -> entries; 39 | 40 | _Py_hashtable_destroy (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/python/run-python.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "hashtable.h" 5 | #include "rhash.h" 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | #define INT_VAL_SIZE sizeof (unsigned) 10 | 11 | static Py_uhash_t _Py_hashtable_hash_str (const void * key) 12 | { 13 | return python_hash (key); 14 | } 15 | 16 | 17 | static int _Py_hashtable_compare_string (const void * key, const _Py_hashtable_entry_t * entry) 18 | { 19 | return ! strcmp (entry -> key, key); 20 | } 21 | 22 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 23 | 24 | #include "python-udb.c" 25 | #include "python-grow.c" 26 | 27 | 28 | int main (int argc, char * argv []) 29 | { 30 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 31 | } 32 | -------------------------------------------------------------------------------- /src/rdestl/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-rde.cpp 3 | 4 | C++FLAGS = -std=c++11 5 | C++FLAGS += -Wno-sign-compare 6 | C++FLAGS += -Wno-unused-value 7 | SYSLIBS += -lstdc++ 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/rdestl/functional.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FUNCTIONAL_H 2 | #define RDESTL_FUNCTIONAL_H 3 | 4 | namespace rde 5 | { 6 | //============================================================================= 7 | template 8 | struct less 9 | { 10 | bool operator()(const T& lhs, const T& rhs) const 11 | { 12 | return lhs < rhs; 13 | } 14 | }; 15 | 16 | //============================================================================= 17 | template 18 | struct greater 19 | { 20 | bool operator()(const T& lhs, const T& rhs) const 21 | { 22 | return lhs > rhs; 23 | } 24 | }; 25 | 26 | //============================================================================= 27 | template 28 | struct equal_to 29 | { 30 | bool operator()(const T& lhs, const T& rhs) const 31 | { 32 | return lhs == rhs; 33 | } 34 | }; 35 | 36 | } 37 | 38 | //----------------------------------------------------------------------------- 39 | #endif // #ifndef RDESTL_FUNCTIONAL_H 40 | -------------------------------------------------------------------------------- /src/rdestl/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_HASH_H 2 | #define RDESTL_HASH_H 3 | 4 | namespace rde 5 | { 6 | 7 | typedef unsigned long hash_value_t; 8 | 9 | // Default implementations, just casts to hash_value. 10 | template 11 | hash_value_t extract_int_key_value(const T& t) 12 | { 13 | return (hash_value_t)t; 14 | } 15 | 16 | // Default implementation of hasher. 17 | // Works for keys that can be converted to 32-bit integer 18 | // with extract_int_key_value. 19 | // Algorithm by Robert Jenkins. 20 | // (see http://www.cris.com/~Ttwang/tech/inthash.htm for example). 21 | template 22 | struct hash 23 | { 24 | hash_value_t operator()(const T& t) const 25 | { 26 | hash_value_t a = extract_int_key_value(t); 27 | a = (a+0x7ed55d16) + (a<<12); 28 | a = (a^0xc761c23c) ^ (a>>19); 29 | a = (a+0x165667b1) + (a<<5); 30 | a = (a+0xd3a2646c) ^ (a<<9); 31 | a = (a+0xfd7046c5) + (a<<3); 32 | a = (a^0xb55a4f09) ^ (a>>16); 33 | return a; 34 | } 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/rdestl/int_to_type.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_INT_TO_TYPE_H 2 | #define RDESTL_INT_TO_TYPE_H 3 | 4 | namespace rde 5 | { 6 | 7 | /** 8 | * Sample usage: 9 | * void fun(int_to_type) { ... } 10 | * void fun(int_to_type) { ... } 11 | * template void bar() 12 | * { 13 | * fun(int_to_type::is_exact>()) 14 | * } 15 | */ 16 | template 17 | struct int_to_type 18 | { 19 | enum 20 | { 21 | value = TVal 22 | }; 23 | }; 24 | 25 | } // namespaces 26 | 27 | #endif // #ifndef RDESTL_INT_TO_TYPE_H 28 | -------------------------------------------------------------------------------- /src/rdestl/rde-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (rde::pair (keys [i], i)); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned grow_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (rde::pair (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/rdestl/rde-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (rde::pair (keys [i], i)); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (rde::pair (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/rdestl/run-rde.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | 6 | /* The implementation */ 7 | #include "hash_map.h" 8 | 9 | 10 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 11 | 12 | struct eqstr 13 | { 14 | inline bool operator () (const char * s1, const char * s2) const 15 | { 16 | return strcmp (s1, s2) == 0; 17 | } 18 | }; 19 | 20 | 21 | struct hasher 22 | { 23 | inline rde::hash_value_t operator () (const char * s) const 24 | { 25 | rde::hash_value_t hash (0); 26 | char c; 27 | while ((c = * s ++) != 0) 28 | hash = (hash << 5) + hash + c; 29 | return hash; 30 | } 31 | }; 32 | 33 | 34 | typedef rde::hash_map hashtable_int_t; 35 | typedef rde::hash_map hashtable_str_t; 36 | 37 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 38 | 39 | #include "rde-udb.cpp" 40 | #include "rde-grow.cpp" 41 | 42 | 43 | int main (int argc, char * argv []) 44 | { 45 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 46 | } 47 | -------------------------------------------------------------------------------- /src/redis/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = dict.c 3 | SRCS += zmalloc.c 4 | LIB = lib-kbench-redis.a 5 | MAINSRCS = run-redis.c 6 | 7 | CFLAGS += -Wno-int-to-pointer-cast 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/redis/grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | dict * ht = dictCreate (& int_dict, NULL); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | dictAdd (ht, (void *) keys [i], (void *) keys [i]); 10 | 11 | count = dictSize (ht); 12 | 13 | dictRelease (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | dict * ht = dictCreate (& str_dict, NULL); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | dictAdd (ht, keys [i], (void *) i); 27 | 28 | count = dictSize (ht); 29 | 30 | dictRelease (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/redis/udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | dict * ht = dictCreate (& int_dict, NULL); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (dictFind (ht, (void *) keys [i])) 11 | dictDelete (ht, (void *) keys [i]); 12 | else 13 | dictAdd (ht, (void *) keys [i], (void *) keys [i]); 14 | } 15 | 16 | count = dictSize (ht); 17 | 18 | dictRelease (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | dict * ht = dictCreate (& str_dict, NULL); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (dictFind (ht, keys [i])) 33 | dictDelete (ht, keys [i]); 34 | else 35 | dictAdd (ht, keys [i], (void *) i); 36 | } 37 | 38 | count = dictSize (ht); 39 | 40 | dictRelease (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/rigtorp-hashmap/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-rigtorp.cpp 3 | 4 | C++FLAGS = -Wno-sign-compare 5 | SYSLIBS += -lstdc++ 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/rigtorp-hashmap/grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | /* Create a HashMap with n buckets and -1 as the empty key */ 5 | hashtable_int_t * ht = new hashtable_int_t (n, -1); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | ht -> insert ({keys [i], keys [i]}); 11 | 12 | count = ht -> size (); 13 | 14 | delete ht; 15 | 16 | return count; 17 | } 18 | 19 | 20 | unsigned grow_str (unsigned n, char ** keys) 21 | { 22 | /* Create a HashMap with n buckets and "" as the empty key */ 23 | hashtable_str_t * ht = new hashtable_str_t (n, (char *)""); 24 | unsigned i; 25 | unsigned count; 26 | 27 | for (i = 0; i < n; i ++) 28 | ht -> insert ({keys [i], i}); 29 | 30 | count = ht -> size (); 31 | 32 | delete ht; 33 | 34 | return count; 35 | } 36 | -------------------------------------------------------------------------------- /src/rigtorp-hashmap/run-rigtorp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "benchmark.h" 5 | #include "rhash.h" 6 | 7 | /* The implementation */ 8 | #include "HashMap.h" 9 | using namespace rigtorp; 10 | 11 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 12 | 13 | struct hasher 14 | { 15 | unsigned operator () (char * key) { return python_hash (key); } 16 | }; 17 | 18 | 19 | struct equaler 20 | { 21 | inline bool operator () (char * s1, char * s2) { return ! strcmp (s1, s2); } 22 | }; 23 | 24 | 25 | typedef rigtorp::HashMap hashtable_int_t; 26 | typedef rigtorp::HashMap hashtable_str_t; 27 | 28 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 29 | 30 | #include "udb.cpp" 31 | #include "grow.cpp" 32 | 33 | 34 | int main (int argc, char * argv []) 35 | { 36 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 37 | } 38 | -------------------------------------------------------------------------------- /src/rigtorp-hashmap/udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | /* Create a HashMap with n buckets and -1 as the empty key */ 5 | hashtable_int_t * ht = new hashtable_int_t (n, -1); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | hashtable_int_t::iterator hit = ht -> find (keys [i]); 12 | if (hit != ht -> end ()) 13 | ht -> erase (hit); 14 | else 15 | ht -> insert ({keys [i], keys [i]}); 16 | } 17 | 18 | count = ht -> size (); 19 | 20 | delete ht; 21 | 22 | return count; 23 | } 24 | 25 | 26 | unsigned udb_str (unsigned n, char ** keys) 27 | { 28 | /* Create a HashMap with n buckets and "" as the empty key */ 29 | hashtable_str_t * ht = new hashtable_str_t (n, (char *)""); 30 | unsigned i; 31 | unsigned count; 32 | 33 | for (i = 0; i < n; i ++) 34 | { 35 | hashtable_str_t::iterator hit = ht -> find (keys [i]); 36 | if (hit != ht -> end ()) 37 | ht -> erase (hit); 38 | else 39 | ht -> insert ({keys [i], i}); 40 | } 41 | 42 | count = ht -> size (); 43 | 44 | delete ht; 45 | 46 | return count; 47 | } 48 | -------------------------------------------------------------------------------- /src/ruby-st/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = st.c 3 | LIB = lib-kbench-ruby-st.a 4 | MAINSRCS = run-ruby-st.c 5 | 6 | INCLUDE += -Iccan 7 | 8 | include ../../etc/Make.rules 9 | 10 | -------------------------------------------------------------------------------- /src/ruby-st/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name ruby 6 | Module ruby-ht 7 | Author Yukihiro Matsumoto (matz@ruby-lang.org) 8 | Description hash table implementation bundled with ruby (based on st hash table package by Peter Moore @ UCB) 9 | Download http://www.ruby-lang.org/en/downloads 10 | Date 1995, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from the ruby-2.3.1 distribution: 17 | 18 | - st.c 19 | - st.h 20 | - ccan/ 21 | 22 | Both st.c and st.h have been subject to modifications in order to compile the files as a standalone module. 23 | -------------------------------------------------------------------------------- /src/ruby-st/ccan/str/str_debug.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_STR_DEBUG_H 3 | #define CCAN_STR_DEBUG_H 4 | 5 | /* #define CCAN_STR_DEBUG 1 */ 6 | 7 | #ifdef CCAN_STR_DEBUG 8 | /* Because we mug the real ones with macros, we need our own wrappers. */ 9 | int str_isalnum(int i); 10 | int str_isalpha(int i); 11 | int str_isascii(int i); 12 | #if HAVE_ISBLANK 13 | int str_isblank(int i); 14 | #endif 15 | int str_iscntrl(int i); 16 | int str_isdigit(int i); 17 | int str_isgraph(int i); 18 | int str_islower(int i); 19 | int str_isprint(int i); 20 | int str_ispunct(int i); 21 | int str_isspace(int i); 22 | int str_isupper(int i); 23 | int str_isxdigit(int i); 24 | 25 | char *str_strstr(const char *haystack, const char *needle); 26 | char *str_strchr(const char *s, int c); 27 | char *str_strrchr(const char *s, int c); 28 | #endif /* CCAN_STR_DEBUG */ 29 | 30 | #endif /* CCAN_STR_DEBUG_H */ 31 | -------------------------------------------------------------------------------- /src/ruby-st/ruby-st-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | st_table * ht = st_init_numtable (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | /* local variable key is needed by st_insert() (it requires a pointer) */ 11 | st_data_t key = (st_data_t) keys [i]; 12 | st_insert (ht, key, i); 13 | } 14 | 15 | count = ht -> num_entries; 16 | 17 | st_free_table (ht); 18 | 19 | return count; 20 | } 21 | 22 | 23 | unsigned grow_str (unsigned n, char ** keys) 24 | { 25 | st_table * ht = st_init_strtable (); 26 | unsigned i; 27 | unsigned count; 28 | 29 | for (i = 0; i < n; i ++) 30 | st_insert (ht, (st_data_t) keys [i], i); 31 | 32 | count = ht -> num_entries; 33 | 34 | st_free_table (ht); 35 | 36 | return count; 37 | } 38 | -------------------------------------------------------------------------------- /src/ruby-st/ruby-st-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | st_table * ht = st_init_numtable (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | /* local variable key is needed by st_delete() (it requires a pointer) */ 11 | st_data_t key = (st_data_t) keys [i]; 12 | if (st_is_member (ht, key)) 13 | st_delete (ht, & key, NULL); 14 | else 15 | st_insert (ht, key, i); 16 | } 17 | 18 | count = ht -> num_entries; 19 | 20 | st_free_table (ht); 21 | 22 | return count; 23 | } 24 | 25 | 26 | unsigned udb_str (unsigned n, char ** keys) 27 | { 28 | st_table * ht = st_init_strtable (); 29 | unsigned i; 30 | unsigned count; 31 | 32 | for (i = 0; i < n; i ++) 33 | { 34 | /* local variable key is needed by st_delete() (it requires a pointer) */ 35 | st_data_t key = (st_data_t) keys [i]; 36 | if (st_is_member (ht, (st_data_t) keys [i])) 37 | st_delete (ht, & key, NULL); 38 | else 39 | st_insert (ht, (st_data_t) keys [i], i); 40 | } 41 | 42 | count = ht -> num_entries; 43 | 44 | st_free_table (ht); 45 | 46 | return count; 47 | } 48 | -------------------------------------------------------------------------------- /src/ruby-st/run-ruby-st.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "st.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #include "ruby-st-udb.c" 11 | #include "ruby-st-grow.c" 12 | 13 | 14 | int main (int argc, char * argv []) 15 | { 16 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 17 | } 18 | -------------------------------------------------------------------------------- /src/run-it/AUTHORS: -------------------------------------------------------------------------------- 1 | Heng Li (lh3@me.com) 2 | ==================== 3 | 4 | http://lh3lh3.users.sourceforge.net 5 | http://github.com/lh3 6 | 7 | http://github.com/attractivechaos 8 | 9 | -------------------------------------------------------------------------------- /src/run-it/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = runlib.c 3 | SRCS += benchmark.c 4 | LIB = libudb.a 5 | MAINSRCS = run-it.c 6 | 7 | SYSLIBS = -lpthread 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/run-it/benchmark.h: -------------------------------------------------------------------------------- 1 | #ifndef UDB_BENCHMARK_H 2 | #define UDB_BENCHMARK_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* Dataset init functions */ 9 | void udb_init_data (unsigned n); 10 | void grow_init_data (unsigned n); 11 | 12 | unsigned udb_benchmark (int argc, char * argv [], 13 | unsigned (* udb_int) (unsigned, unsigned *), 14 | unsigned (* udb_str) (unsigned, char **), 15 | unsigned (* grow_int) (unsigned, unsigned *), 16 | unsigned (* grow_str) (unsigned, char **) 17 | ); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* ! _UDB_BENCHMARK_H_ */ 24 | -------------------------------------------------------------------------------- /src/run-it/rhash.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | /* Stolen from java 1.4 source (as found in Niels Provos's hash table) */ 5 | static inline unsigned java_hash (unsigned h) 6 | { 7 | h += ~(h << 9); 8 | h ^= ((h >> 14) | (h << 18)); /* >>> */ 9 | h += (h << 4); 10 | h ^= ((h >> 10) | (h << 22)); /* >>> */ 11 | return h; 12 | } 13 | 14 | 15 | /* Basic string hash function from Python (as found in Niels Provos's hash table) */ 16 | static inline unsigned python_hash (const char * s) 17 | { 18 | unsigned h; 19 | const unsigned char * cp = (const unsigned char *) s; 20 | h = * cp << 7; 21 | while (* cp) 22 | h = (1000003 * h) ^ * cp ++; 23 | 24 | /* This conversion truncates the length of the string, but that's ok */ 25 | h ^= (unsigned) (cp - (const unsigned char *) s); 26 | 27 | return h; 28 | } 29 | 30 | 31 | /* 32 | * MurmurHash3 33 | * https://github.com/aappleby/smhasher 34 | */ 35 | static inline uint32_t MurmurHash3 (uint32_t h) 36 | { 37 | h ^= h >> 16; 38 | h *= 0x85ebca6b; 39 | h ^= h >> 13; 40 | h *= 0xc2b2ae35; 41 | h ^= h >> 16; 42 | return h; 43 | } 44 | -------------------------------------------------------------------------------- /src/run-it/runlib.h: -------------------------------------------------------------------------------- 1 | #ifndef LH3_RUNLIB_H_ 2 | #define LH3_RUNLIB_H_ 3 | 4 | #include 5 | 6 | #define RUN_ERR_WRONG_OS 1 7 | #define RUN_ERR_MISSING_INFO 2 8 | #define RUN_ERR_PROC_FINISHED 3 9 | 10 | 11 | /* static system information */ 12 | typedef struct 13 | { 14 | size_t mem_total; 15 | size_t page_size; 16 | size_t swap_total; 17 | 18 | } RunSysStatic; 19 | 20 | 21 | /* dynamic system information */ 22 | typedef struct 23 | { 24 | double wall_clock; 25 | size_t mem_free; 26 | size_t mem_available; 27 | 28 | } RunSysDyn; 29 | 30 | 31 | /* dynamic process information */ 32 | typedef struct 33 | { 34 | size_t rss, vsize; 35 | double utime, stime; 36 | 37 | } RunProcDyn; 38 | 39 | 40 | int run_get_static_sys_info (RunSysStatic * rss); 41 | int run_get_dynamic_sys_info (RunSysDyn * rsd); 42 | int run_get_dynamic_proc_info (pid_t pid, RunProcDyn * rpd); 43 | 44 | #endif /* ! LH3_RUNLIB_H_ */ 45 | -------------------------------------------------------------------------------- /src/sglib/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-sglib.c 3 | 4 | include ../../etc/Make.rules 5 | -------------------------------------------------------------------------------- /src/sglib/sglib-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t * objs = objs_unsigned (keys, n); 5 | obj_t ** ht = calloc (HASHSIZE, sizeof (* ht)); 6 | unsigned i; 7 | unsigned count; 8 | 9 | sglib_hashed_obj_t_init (ht); 10 | 11 | for (i = 0; i < n; i ++) 12 | sglib_hashed_obj_t_add (ht, & objs [i]); 13 | 14 | count = sglib_hashed_obj_t_size (ht); 15 | 16 | free (ht); 17 | free (objs); 18 | 19 | return count; 20 | } 21 | 22 | 23 | unsigned grow_str (unsigned n, char ** keys) 24 | { 25 | obj_t * objs = objs_str (keys, n); 26 | obj_t ** ht = calloc (HASHSIZE, sizeof (* ht)); 27 | unsigned i; 28 | unsigned count; 29 | 30 | sglib_hashed_obj_t_init (ht); 31 | 32 | for (i = 0; i < n; i ++) 33 | sglib_hashed_obj_t_add (ht, & objs [i]); 34 | 35 | count = sglib_hashed_obj_t_size (ht); 36 | 37 | free (ht); 38 | free (objs); 39 | 40 | return count; 41 | } 42 | -------------------------------------------------------------------------------- /src/sglib/sglib-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t * objs = objs_unsigned (keys, n); 5 | obj_t ** ht = calloc (HASHSIZE, sizeof (* ht)); 6 | unsigned i; 7 | unsigned count; 8 | 9 | sglib_hashed_obj_t_init (ht); 10 | 11 | for (i = 0; i < n; i ++) 12 | { 13 | obj_t * hit = sglib_hashed_obj_t_find_member (ht, & objs [i]); 14 | if (hit) 15 | sglib_hashed_obj_t_delete_if_member (ht, & objs [i], & hit); 16 | else 17 | sglib_hashed_obj_t_add (ht, & objs [i]); 18 | } 19 | 20 | count = sglib_hashed_obj_t_size (ht); 21 | 22 | free (ht); 23 | free (objs); 24 | 25 | return count; 26 | } 27 | 28 | 29 | unsigned udb_str (unsigned n, char ** keys) 30 | { 31 | obj_t * objs = objs_str (keys, n); 32 | obj_t ** ht = calloc (HASHSIZE, sizeof (* ht)); 33 | unsigned i; 34 | unsigned count; 35 | 36 | sglib_hashed_obj_t_init (ht); 37 | 38 | for (i = 0; i < n; i ++) 39 | { 40 | obj_t * hit = sglib_hashed_obj_t_find_member (ht, & objs [i]); 41 | if (hit) 42 | sglib_hashed_obj_t_delete_if_member (ht, & objs [i], & hit); 43 | else 44 | sglib_hashed_obj_t_add (ht, & objs [i]); 45 | } 46 | 47 | count = sglib_hashed_obj_t_size (ht); 48 | 49 | free (ht); 50 | free (objs); 51 | 52 | return count; 53 | } 54 | -------------------------------------------------------------------------------- /src/st/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = st.c 3 | LIB = lib-kbench-st.a 4 | MAINSRCS = run-st.c 5 | 6 | include ../../etc/Make.rules 7 | -------------------------------------------------------------------------------- /src/st/ORG-st.h: -------------------------------------------------------------------------------- 1 | /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */ 2 | 3 | /* @(#) st.h 5.1 89/12/14 */ 4 | 5 | #ifndef ST_INCLUDED 6 | 7 | #define ST_INCLUDED 8 | 9 | typedef struct st_table st_table; 10 | 11 | struct st_hash_type { 12 | int (*compare)(); 13 | int (*hash)(); 14 | }; 15 | 16 | struct st_table { 17 | struct st_hash_type *type; 18 | int num_bins; 19 | int num_entries; 20 | struct st_table_entry **bins; 21 | }; 22 | 23 | #define st_is_member(table,key) st_lookup(table,key,(char **)0) 24 | 25 | enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE}; 26 | 27 | st_table *st_init_table(); 28 | st_table *st_init_table_with_size(); 29 | st_table *st_init_numtable(); 30 | st_table *st_init_numtable_with_size(); 31 | st_table *st_init_strtable(); 32 | st_table *st_init_strtable_with_size(); 33 | int st_delete(), st_delete_safe(); 34 | int st_insert(), st_lookup(); 35 | void st_foreach(), st_add_direct(), st_free_table(), st_cleanup_safe(); 36 | st_table *st_copy(); 37 | 38 | #define ST_NUMCMP ((int (*)()) 0) 39 | #define ST_NUMHASH ((int (*)()) -2) 40 | 41 | #define st_numcmp ST_NUMCMP 42 | #define st_numhash ST_NUMHASH 43 | 44 | int st_strhash(); 45 | 46 | #endif /* ST_INCLUDED */ 47 | -------------------------------------------------------------------------------- /src/st/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name Peter Moore's hash table 6 | Module st 7 | Author Peter Moore @ UCB 8 | Description general purpose hash table package 9 | Download used in several projects (bundled with Ruby and Oniguruma) 10 | Date 1989 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from a github copy included in hash_benchmark project by Andre' Medeiros available at: 17 | http://github.com/andremedeiros/hash_benchmark 18 | 19 | - st.h 20 | - st.c 21 | 22 | No modification was needed to compile the files as a standalone module. 23 | 24 | 25 | The other 2 files in this directory: 26 | ORG-st.h 27 | ORG-st.c 28 | were downloaded from http://opensource.apple.com/source/ruby/ruby-4/ruby/st.[hc]?txt 29 | and they should be by the original files without Ruby's modifications. 30 | -------------------------------------------------------------------------------- /src/st/run-st.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "st.h" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 11 | 12 | #include "st-udb.c" 13 | #include "st-grow.c" 14 | 15 | 16 | int main (int argc, char * argv []) 17 | { 18 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 19 | } 20 | -------------------------------------------------------------------------------- /src/st/st-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | st_table * ht = st_init_numtable (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | /* local variable key is needed by st_insert() (it requires a pointer) */ 11 | st_data_t key = (st_data_t) keys [i]; 12 | st_insert (ht, key, i); 13 | } 14 | 15 | count = ht -> num_entries; 16 | 17 | st_free_table (ht); 18 | 19 | return count; 20 | } 21 | 22 | 23 | unsigned grow_str (unsigned n, char ** keys) 24 | { 25 | st_table * ht = st_init_strtable (); 26 | unsigned i; 27 | unsigned count; 28 | 29 | for (i = 0; i < n; i ++) 30 | st_insert (ht, (st_data_t) keys [i], i); 31 | 32 | count = ht -> num_entries; 33 | 34 | st_free_table (ht); 35 | 36 | return count; 37 | } 38 | -------------------------------------------------------------------------------- /src/st/st-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | st_table * ht = st_init_numtable (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | /* local variable key is needed by st_delete() (it requires a pointer) */ 11 | st_data_t key = (st_data_t) keys [i]; 12 | if (st_is_member (ht, key)) 13 | st_delete (ht, & key, NULL); 14 | else 15 | st_insert (ht, key, i); 16 | } 17 | 18 | count = ht -> num_entries; 19 | 20 | st_free_table (ht); 21 | 22 | return count; 23 | } 24 | 25 | 26 | unsigned udb_str (unsigned n, char ** keys) 27 | { 28 | st_table * ht = st_init_strtable (); 29 | unsigned i; 30 | unsigned count; 31 | 32 | for (i = 0; i < n; i ++) 33 | { 34 | /* local variable key is needed by st_delete() (it requires a pointer) */ 35 | st_data_t key = (st_data_t) keys [i]; 36 | if (st_is_member (ht, (st_data_t) keys [i])) 37 | st_delete (ht, & key, NULL); 38 | else 39 | st_insert (ht, (st_data_t) keys [i], i); 40 | } 41 | 42 | count = ht -> num_entries; 43 | 44 | st_free_table (ht); 45 | 46 | return count; 47 | } 48 | -------------------------------------------------------------------------------- /src/stb/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-stb.c 3 | 4 | WFLAGS = -Wno-strict-aliasing 5 | WFLAGS += -Wno-pointer-to-int-cast 6 | WFLAGS += -Wno-unused-value 7 | WFLAGS += -Wno-unused-but-set-variable 8 | WFLAGS += -Wno-unused-function 9 | WFLAGS += -Wno-maybe-uninitialized 10 | WFLAGS += -Wno-strict-overflow 11 | WFLAGS += -Wno-return-type 12 | 13 | include ../../etc/Make.rules 14 | -------------------------------------------------------------------------------- /src/stb/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name stb 6 | Module idict && sdict 7 | Author Sean T. Barrett (sean@nothings.org) 8 | Description single-file public domain libraries for C/C++ 9 | Download http://github.com/nothings/stb 10 | Date 2009 11 | Language C macro 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from latest git version: 17 | 18 | - stb.h 19 | 20 | + I hacked a bit the header file in order to eliminate all the code that is not related to the hash tables 21 | ! Fixed a segmentation violation due to conditional jump on an initialized value (malloc replaced with calloc) 22 | -------------------------------------------------------------------------------- /src/stb/run-stb.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #define STB_DEFINE 5 | #include "stb.h" 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | #include "stb-udb.c" 12 | #include "stb-grow.c" 13 | 14 | 15 | int main (int argc, char * argv []) 16 | { 17 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 18 | } 19 | -------------------------------------------------------------------------------- /src/stb/stb-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | stb_idict * ht = stb_idict_create (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | stb_idict_set (ht, keys [i], keys [i]); 10 | 11 | count = ht -> count; 12 | 13 | stb_idict_destroy (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | stb_sdict * ht = stb_sdict_new (0); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | stb_sdict_set (ht, keys [i], & i); 27 | 28 | count = ht -> count; 29 | 30 | stb_sdict_destroy (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/stb/stb-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | stb_idict * ht = stb_idict_create (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | int hit; 11 | if (stb_idict_get_flag (ht, keys [i], & hit)) 12 | stb_idict_remove (ht, keys [i], & hit); 13 | else 14 | stb_idict_set (ht, keys [i], keys [i]); 15 | } 16 | 17 | count = ht -> count; 18 | 19 | stb_idict_destroy (ht); 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | stb_sdict * ht = stb_sdict_new (0); 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | if (stb_sdict_get (ht, keys [i])) 34 | stb_sdict_remove (ht, keys [i], NULL); 35 | else 36 | stb_sdict_set (ht, keys [i], & i); 37 | } 38 | 39 | count = ht -> count; 40 | 41 | stb_sdict_destroy (ht); 42 | 43 | return count; 44 | } 45 | -------------------------------------------------------------------------------- /src/sys-LuaHashMap/LuaHashMap-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | LuaHashMap * ht = LuaHashMap_Create (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | LuaHashMap_SetValueIntegerForKeyInteger (ht, keys [i], keys [i]); 10 | 11 | count = LuaHashMap_Count (ht); 12 | 13 | LuaHashMap_Free (ht); 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | LuaHashMap * ht = LuaHashMap_Create (); 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | LuaHashMap_SetValueIntegerForKeyString (ht, i, keys [i]); 27 | 28 | count = LuaHashMap_Count (ht); 29 | 30 | LuaHashMap_Free (ht); 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/sys-LuaHashMap/LuaHashMap-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | LuaHashMap * ht = LuaHashMap_Create (); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (LuaHashMap_GetValueIntegerForKeyInteger (ht, keys [i]) == keys [i]) 11 | LuaHashMap_RemoveKeyInteger (ht, keys [i]); 12 | else 13 | LuaHashMap_SetValueIntegerForKeyInteger (ht, keys [i], keys [i]); 14 | } 15 | 16 | count = LuaHashMap_Count (ht); 17 | 18 | LuaHashMap_Free (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | LuaHashMap * ht = LuaHashMap_Create (); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (LuaHashMap_GetValueIntegerForKeyString (ht, keys [i])) 33 | LuaHashMap_RemoveKeyString (ht, keys [i]); 34 | else 35 | LuaHashMap_SetValueIntegerForKeyString (ht, i, keys [i]); 36 | } 37 | 38 | count = LuaHashMap_Count (ht); 39 | 40 | LuaHashMap_Free (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/sys-LuaHashMap/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = LuaHashMap.c 3 | LIB = lib-kbench-luahashmap.a 4 | MAINSRCS = run-luahashmap.c 5 | 6 | INCLUDE += `pkg-config --cflags lua-5.3` 7 | SYSLIBS += `pkg-config --libs lua-5.3` 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/sys-LuaHashMap/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name LuaHashMap 6 | Module hashmap 7 | Author Eric Wing (ewing@playcontrolnet) 8 | Description An easy to use hash table library for C 9 | Download http://playcontrol.net/opensource/LuaHashMap 10 | Date 2011, 2012 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install liblua5.3-dev 16 | 17 | The following sources files were locally copied from a git clone available at: 18 | https://github.com/helloj/luahashmap 19 | 20 | - LuaHashMap.h 21 | - LuaHashMap.c 22 | 23 | No modifications were needed in order to compile the files as a standalone module. 24 | -------------------------------------------------------------------------------- /src/sys-LuaHashMap/run-luahashmap.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "LuaHashMap.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #include "LuaHashMap-udb.c" 11 | #include "LuaHashMap-grow.c" 12 | 13 | 14 | int main (int argc, char * argv []) 15 | { 16 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 17 | } 18 | -------------------------------------------------------------------------------- /src/sys-Qt/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-hash.cpp 3 | C++MAINSRCS += run-map.cpp 4 | 5 | C++FLAGS = -std=c++11 6 | C++FLAGS += -Wno-sign-compare 7 | C++FLAGS += -fPIC 8 | INCLUDE += `pkg-config --cflags Qt5Core` 9 | SYSLIBS += `pkg-config --libs Qt5Core` 10 | SYSLIBS += -lstdc++ 11 | 12 | include ../../etc/Make.rules 13 | -------------------------------------------------------------------------------- /src/sys-Qt/qt-hash-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert (keys [i], keys [i]); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t; 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | { 27 | mystr_t p; 28 | hashtable_str_t::const_iterator hit; 29 | 30 | p . str = keys [i]; 31 | ht -> insert (p, i); 32 | } 33 | 34 | count = ht -> size (); 35 | 36 | delete ht; 37 | 38 | return count; 39 | } 40 | -------------------------------------------------------------------------------- /src/sys-Qt/qt-hash-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> remove (keys [i]); 13 | else 14 | ht -> insert (keys [i], keys [i]); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | mystr_t p; 34 | hashtable_str_t::const_iterator hit; 35 | 36 | p . str = keys [i]; 37 | hit = ht -> find (p); 38 | if (hit != ht -> end ()) 39 | ht -> remove (p); 40 | else 41 | ht -> insert (p, i); 42 | } 43 | 44 | count = ht -> size (); 45 | 46 | delete ht; 47 | 48 | return count; 49 | } 50 | -------------------------------------------------------------------------------- /src/sys-Qt/qt-map-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> remove (keys [i]); 13 | else 14 | ht -> insert (keys [i], keys [i]); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned grow_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::const_iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> remove (keys [i]); 36 | else 37 | ht -> insert (keys [i], i); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/sys-Qt/qt-map-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> remove (keys [i]); 13 | else 14 | ht -> insert (keys [i], keys [i]); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::const_iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> remove (keys [i]); 36 | else 37 | ht -> insert (keys [i], i); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/sys-Qt/run-hash.cpp: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include 5 | #include 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | struct mystr_t 10 | { 11 | const char * str; 12 | }; 13 | 14 | typedef QHash hashtable_int_t; 15 | typedef QHash hashtable_str_t; 16 | 17 | inline bool operator == (const mystr_t & a, const mystr_t & b) { return strcmp (a . str, b . str) == 0; } 18 | 19 | static inline unsigned __ac_X31_hash_string (const char * s) 20 | { 21 | unsigned h = * s; 22 | if (h) 23 | for (++ s; * s; ++ s) 24 | h = (h << 5) - h + * s; 25 | return h; 26 | } 27 | 28 | 29 | inline uint qHash (const mystr_t & a) 30 | { 31 | return __ac_X31_hash_string (a . str); 32 | } 33 | 34 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 35 | 36 | #include "qt-hash-udb.cpp" 37 | #include "qt-hash-grow.cpp" 38 | 39 | 40 | int main (int argc, char * argv []) 41 | { 42 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 43 | } 44 | -------------------------------------------------------------------------------- /src/sys-Qt/run-map.cpp: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include 5 | #include 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | typedef QMap hashtable_int_t; 10 | typedef QMap hashtable_str_t; 11 | 12 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 13 | 14 | #include "qt-map-udb.cpp" 15 | #include "qt-map-grow.cpp" 16 | 17 | 18 | int main (int argc, char * argv []) 19 | { 20 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 21 | } 22 | -------------------------------------------------------------------------------- /src/sys-apr/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-apr-lib.c 3 | 4 | SYSLIBS += -lapr-1 -lpthread 5 | 6 | include ../../etc/Make.rules 7 | -------------------------------------------------------------------------------- /src/sys-apr/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name apr 6 | Module hashtable 7 | Author Apache Software Foundation (ASF) 8 | Description Apache Portable Runtime Library 9 | Download http://apache.org 10 | Date 2011, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install libapr1-dev 16 | -------------------------------------------------------------------------------- /src/sys-apr/apr-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | apr_pool_t * p; 5 | apr_hash_t * ht; 6 | unsigned i; 7 | unsigned count; 8 | 9 | apr_pool_initialize (); 10 | apr_pool_create (& p, NULL); 11 | 12 | ht = apr_hash_make (p); 13 | 14 | for (i = 0; i < n; i ++) 15 | { 16 | if (apr_hash_get (ht, & keys [i], sizeof (keys [i]))) 17 | apr_hash_del (ht, & keys [i], sizeof (keys [i])); 18 | else 19 | apr_hash_set (ht, & keys [i], sizeof (keys [i]), & keys [i]); 20 | } 21 | 22 | count = apr_hash_count (ht); 23 | 24 | apr_hash_clear (ht); 25 | apr_pool_destroy (p); 26 | apr_pool_terminate (); 27 | 28 | return count; 29 | } 30 | 31 | 32 | unsigned grow_str (unsigned n, char ** keys) 33 | { 34 | apr_pool_t * p; 35 | apr_hash_t * ht; 36 | unsigned i; 37 | unsigned count; 38 | 39 | apr_pool_initialize (); 40 | apr_pool_create (& p, NULL); 41 | 42 | ht = apr_hash_make (p); 43 | 44 | for (i = 0; i < n; i ++) 45 | { 46 | if (apr_hash_get (ht, keys [i], strlen (keys [i]))) 47 | apr_hash_del (ht, keys [i], strlen (keys [i])); 48 | else 49 | apr_hash_set (ht, keys [i], strlen (keys [i]), keys [i]); 50 | } 51 | 52 | count = apr_hash_count (ht); 53 | 54 | apr_hash_clear (ht); 55 | apr_pool_destroy (p); 56 | apr_pool_terminate (); 57 | 58 | return count; 59 | } 60 | -------------------------------------------------------------------------------- /src/sys-apr/apr-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | apr_pool_t * p; 5 | apr_hash_t * ht; 6 | unsigned i; 7 | unsigned count; 8 | 9 | apr_pool_initialize (); 10 | apr_pool_create (& p, NULL); 11 | 12 | ht = apr_hash_make (p); 13 | 14 | for (i = 0; i < n; i ++) 15 | { 16 | if (apr_hash_get (ht, & keys [i], sizeof (keys [i]))) 17 | apr_hash_del (ht, & keys [i], sizeof (keys [i])); 18 | else 19 | apr_hash_set (ht, & keys [i], sizeof (keys [i]), & keys [i]); 20 | } 21 | 22 | count = apr_hash_count (ht); 23 | 24 | apr_hash_clear (ht); 25 | apr_pool_destroy (p); 26 | apr_pool_terminate (); 27 | 28 | return count; 29 | } 30 | 31 | 32 | unsigned udb_str (unsigned n, char ** keys) 33 | { 34 | apr_pool_t * p; 35 | apr_hash_t * ht; 36 | unsigned i; 37 | unsigned count; 38 | 39 | apr_pool_initialize (); 40 | apr_pool_create (& p, NULL); 41 | 42 | ht = apr_hash_make (p); 43 | 44 | for (i = 0; i < n; i ++) 45 | { 46 | if (apr_hash_get (ht, keys [i], strlen (keys [i]))) 47 | apr_hash_del (ht, keys [i], strlen (keys [i])); 48 | else 49 | apr_hash_set (ht, keys [i], strlen (keys [i]), keys [i]); 50 | } 51 | 52 | count = apr_hash_count (ht); 53 | 54 | apr_hash_clear (ht); 55 | apr_pool_destroy (p); 56 | apr_pool_terminate (); 57 | 58 | return count; 59 | } 60 | -------------------------------------------------------------------------------- /src/sys-apr/run-apr-lib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #define __USE_LARGEFILE64 7 | #include 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | #define apr_hash_del(x, y, z) apr_hash_set(x, y, z, NULL) 12 | 13 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 14 | 15 | #include "apr-udb.c" 16 | #include "apr-grow.c" 17 | 18 | 19 | int main (int argc, char * argv []) 20 | { 21 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 22 | } 23 | -------------------------------------------------------------------------------- /src/sys-boost/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-unordered-map.cpp 3 | 4 | C++FLAGS = -std=c++11 5 | C++FLAGS += -Wno-sign-compare 6 | SYSLIBS += -lstdc++ 7 | SYSLIBS += -lm 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/sys-boost/boost-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t; 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 27 | 28 | count = ht -> size (); 29 | 30 | delete ht; 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/sys-boost/boost-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::const_iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/sys-boost/run-unordered-map.cpp: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include 5 | #include 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | typedef boost::unordered_map hashtable_int_t; 10 | typedef boost::unordered_map hashtable_str_t; 11 | 12 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 13 | 14 | #include "boost-udb.cpp" 15 | #include "boost-grow.cpp" 16 | 17 | int main (int argc, char * argv []) 18 | { 19 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 20 | } 21 | -------------------------------------------------------------------------------- /src/sys-gcc-stl/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-unordered-map.cpp 3 | C++MAINSRCS += run-map.cpp 4 | 5 | C++FLAGS = -std=c++11 6 | C++FLAGS += -Wno-sign-compare 7 | SYSLIBS += -lstdc++ 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/sys-gcc-stl/g++-map-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t; 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 27 | 28 | count = ht -> size (); 29 | 30 | delete ht; 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/sys-gcc-stl/g++-map-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit -> first); 13 | else 14 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::const_iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit -> first); 36 | else 37 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/sys-gcc-stl/g++-unordered-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 10 | 11 | count = ht -> size (); 12 | 13 | delete ht; 14 | 15 | return count; 16 | } 17 | 18 | 19 | unsigned grow_str (unsigned n, char ** keys) 20 | { 21 | hashtable_str_t * ht = new hashtable_str_t; 22 | unsigned i; 23 | unsigned count; 24 | 25 | for (i = 0; i < n; i ++) 26 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 27 | 28 | count = ht -> size (); 29 | 30 | delete ht; 31 | 32 | return count; 33 | } 34 | -------------------------------------------------------------------------------- /src/sys-gcc-stl/g++-unordered-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 11 | if (hit != ht -> end ()) 12 | ht -> erase (hit); 13 | else 14 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 15 | } 16 | 17 | count = ht -> size (); 18 | 19 | delete ht; 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned udb_str (unsigned n, char ** keys) 26 | { 27 | hashtable_str_t * ht = new hashtable_str_t; 28 | unsigned i; 29 | unsigned count; 30 | 31 | for (i = 0; i < n; i ++) 32 | { 33 | hashtable_str_t::const_iterator hit = ht -> find (keys [i]); 34 | if (hit != ht -> end ()) 35 | ht -> erase (hit); 36 | else 37 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 38 | } 39 | 40 | count = ht -> size (); 41 | 42 | delete ht; 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/sys-gcc-stl/run-map.cpp: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "map" 5 | #include 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | typedef std::map hashtable_int_t; 10 | typedef std::map hashtable_str_t; 11 | 12 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 13 | 14 | #include "g++-map-udb.cpp" 15 | #include "g++-map-grow.cpp" 16 | 17 | 18 | int main (int argc, char * argv []) 19 | { 20 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 21 | } 22 | -------------------------------------------------------------------------------- /src/sys-gcc-stl/run-unordered-map.cpp: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include 5 | #include 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | typedef std::unordered_map hashtable_int_t; 10 | typedef std::unordered_map hashtable_str_t; 11 | 12 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 13 | 14 | #include "g++-unordered-udb.cpp" 15 | #include "g++-unordered-grow.cpp" 16 | 17 | 18 | int main (int argc, char * argv []) 19 | { 20 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 21 | } 22 | -------------------------------------------------------------------------------- /src/sys-glib/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-glib.c 3 | 4 | INCLUDE += `pkg-config --cflags glib-2.0` 5 | SYSLIBS += `pkg-config --libs glib-2.0` -lm 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/sys-glib/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name glib2.0 6 | Module hashtable 7 | Author Peter Mattis, Spencer Kimball and Josh MacDonald 8 | Description Library of useful routines for C programming 9 | Download http://gnu.org 10 | Date 1995, 1997 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install libglib2.0-dev 16 | -------------------------------------------------------------------------------- /src/sys-glib/glib-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | GHashTable * ht = g_hash_table_new (g_int_hash, g_int_equal); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (g_hash_table_contains (ht, & keys [i])) 11 | g_hash_table_remove (ht, & keys [i]); 12 | else 13 | g_hash_table_insert (ht, (gpointer) & keys [i], (gpointer) & keys [i]); 14 | } 15 | 16 | count = g_hash_table_size (ht); 17 | 18 | g_hash_table_destroy (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned grow_str (unsigned n, char ** keys) 25 | { 26 | GHashTable * ht = g_hash_table_new (g_str_hash, g_str_equal); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (g_hash_table_contains (ht, keys [i])) 33 | g_hash_table_remove (ht, keys [i]); 34 | else 35 | g_hash_table_insert (ht, (gpointer) keys [i], (gpointer) keys [i]); 36 | } 37 | 38 | count = g_hash_table_size (ht); 39 | 40 | g_hash_table_destroy (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/sys-glib/glib-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | GHashTable * ht = g_hash_table_new (g_int_hash, g_int_equal); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | if (g_hash_table_contains (ht, & keys [i])) 11 | g_hash_table_remove (ht, & keys [i]); 12 | else 13 | g_hash_table_insert (ht, (gpointer) & keys [i], (gpointer) & keys [i]); 14 | } 15 | 16 | count = g_hash_table_size (ht); 17 | 18 | g_hash_table_destroy (ht); 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned udb_str (unsigned n, char ** keys) 25 | { 26 | GHashTable * ht = g_hash_table_new (g_str_hash, g_str_equal); 27 | unsigned i; 28 | unsigned count; 29 | 30 | for (i = 0; i < n; i ++) 31 | { 32 | if (g_hash_table_contains (ht, keys [i])) 33 | g_hash_table_remove (ht, keys [i]); 34 | else 35 | g_hash_table_insert (ht, (gpointer) keys [i], (gpointer) keys [i]); 36 | } 37 | 38 | count = g_hash_table_size (ht); 39 | 40 | g_hash_table_destroy (ht); 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/sys-glib/run-glib.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "glib.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | #include "glib-udb.c" 11 | #include "glib-grow.c" 12 | 13 | 14 | int main (int argc, char * argv []) 15 | { 16 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 17 | } 18 | -------------------------------------------------------------------------------- /src/sys-judy/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-judy.c 3 | 4 | CFLAGS += -Wno-pointer-sign 5 | SYSLIBS += -lJudy 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/sys-judy/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Sep 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name judy 6 | Module dynamic array 7 | Author Doug Baskinks (dougbaskins@yahoo.com) 8 | Description Judy - C library creating and accessing dynamic arrays 9 | Download http://judy.sourceforge.net 10 | Date 2004, 2007 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install libjudy-dev 16 | -------------------------------------------------------------------------------- /src/sys-judy/judy-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | Pvoid_t ht = NULL; 5 | unsigned i; 6 | Word_t r; 7 | Word_t count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | Word_t * p; 12 | JLG (p, ht, keys [i]); 13 | JLI (p, ht, keys [i]); 14 | * p = i; 15 | } 16 | 17 | JLC (count, ht, 0, -1); 18 | 19 | JLFA (r, ht); 20 | 21 | return count; 22 | } 23 | 24 | 25 | unsigned grow_str (unsigned n, char ** keys) 26 | { 27 | Pvoid_t ht = NULL; 28 | unsigned i; 29 | Word_t r; 30 | Word_t count; 31 | 32 | for (i = 0; i < n; i ++) 33 | { 34 | Word_t * p; 35 | JSLG (p, ht, (char *) keys [i]); 36 | JSLI (p, ht, keys [i]); 37 | * p = i; 38 | } 39 | 40 | JLC (count, ht, 0, -1); 41 | 42 | JSLFA (r, ht); 43 | 44 | return count; 45 | } 46 | -------------------------------------------------------------------------------- /src/sys-judy/judy-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | Pvoid_t ht = NULL; 5 | unsigned i; 6 | Word_t r; 7 | Word_t count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | Word_t * p; 12 | JLG (p, ht, keys [i]); 13 | if (p) 14 | { 15 | JLD (r, ht, keys [i]); 16 | } 17 | else 18 | { 19 | JLI (p, ht, keys [i]); 20 | * p = i; 21 | } 22 | } 23 | 24 | JLC (count, ht, 0, -1); 25 | 26 | JLFA (r, ht); 27 | 28 | return count; 29 | } 30 | 31 | 32 | unsigned udb_str (unsigned n, char ** keys) 33 | { 34 | Pvoid_t ht = NULL; 35 | unsigned i; 36 | Word_t r; 37 | Word_t count; 38 | 39 | for (i = 0; i < n; i ++) 40 | { 41 | Word_t * p; 42 | JSLG (p, ht, (char *) keys [i]); 43 | if (p) 44 | { 45 | JSLD (r, ht, keys [i]); 46 | } 47 | else 48 | { 49 | JSLI (p, ht, keys [i]); 50 | * p = i; 51 | } 52 | } 53 | 54 | JLC (count, ht, 0, -1); 55 | 56 | JSLFA (r, ht); 57 | 58 | return count; 59 | } 60 | -------------------------------------------------------------------------------- /src/sys-judy/run-judy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 11 | 12 | #include "judy-udb.c" 13 | #include "judy-grow.c" 14 | 15 | 16 | int main (int argc, char * argv []) 17 | { 18 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 19 | } 20 | -------------------------------------------------------------------------------- /src/sys-perl/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-perl.c 3 | 4 | INCLUDE += `perl -MExtUtils::Embed -e ccopts` 5 | SYSLIBS += `perl -MExtUtils::Embed -e ldopts` 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/sys-perl/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name perl 6 | Module hashtable 7 | Author Larry Wall 8 | Description shared Perl library 9 | Download http://perl.org 10 | Date 1993, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install libperl5.22 16 | -------------------------------------------------------------------------------- /src/sys-perl/perl-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | PerlInterpreter * my_perl = perl_alloc (); 5 | HV * ht; 6 | unsigned i; 7 | unsigned count; 8 | 9 | perl_construct (my_perl); 10 | ht = newHV (); 11 | 12 | for (i = 0; i < n; i ++) 13 | { 14 | SV * key = newSViv (keys [i]); 15 | SV * val = newSViv (keys [i]); 16 | hv_store_ent (ht, key, val, 0); 17 | } 18 | 19 | count = HvKEYS (ht); 20 | 21 | hv_clear (ht); 22 | perl_destruct (my_perl); 23 | perl_free (my_perl); 24 | 25 | return count; 26 | } 27 | 28 | 29 | unsigned grow_str (unsigned n, char ** keys) 30 | { 31 | PerlInterpreter * my_perl = perl_alloc (); 32 | HV * ht = newHV (); 33 | unsigned i; 34 | unsigned count; 35 | 36 | perl_construct (my_perl); 37 | 38 | for (i = 0; i < n; i ++) 39 | { 40 | SV * val = newSViv (i); 41 | hv_store (ht, keys [i], strlen (keys [i]), val, 0); 42 | } 43 | 44 | count = HvKEYS (ht); 45 | 46 | hv_clear (ht); 47 | perl_destruct (my_perl); 48 | perl_free (my_perl); 49 | 50 | return count; 51 | } 52 | -------------------------------------------------------------------------------- /src/sys-perl/perl-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | PerlInterpreter * my_perl = perl_alloc (); 5 | HV * ht; 6 | unsigned i; 7 | unsigned count; 8 | 9 | perl_construct (my_perl); 10 | ht = newHV (); 11 | 12 | for (i = 0; i < n; i ++) 13 | { 14 | SV * key = newSViv (keys [i]); 15 | if (hv_fetch_ent (ht, key, 0, 0)) 16 | hv_delete_ent (ht, key, G_DISCARD, 0); 17 | else 18 | { 19 | SV * val = newSViv (keys [i]); 20 | hv_store_ent (ht, key, val, 0); 21 | } 22 | } 23 | 24 | count = HvKEYS (ht); 25 | 26 | hv_clear (ht); 27 | perl_destruct (my_perl); 28 | perl_free (my_perl); 29 | 30 | return count; 31 | } 32 | 33 | 34 | unsigned udb_str (unsigned n, char ** keys) 35 | { 36 | PerlInterpreter * my_perl = perl_alloc (); 37 | HV * ht = newHV (); 38 | unsigned i; 39 | unsigned count; 40 | 41 | perl_construct (my_perl); 42 | 43 | for (i = 0; i < n; i ++) 44 | { 45 | if (hv_fetch (ht, keys [i], strlen (keys [i]), 0)) 46 | hv_delete (ht, keys [i], strlen (keys [i]), G_DISCARD); 47 | else 48 | { 49 | SV * val = newSViv (i); 50 | hv_store (ht, keys [i], strlen (keys [i]), val, 0); 51 | } 52 | } 53 | 54 | count = HvKEYS (ht); 55 | 56 | hv_clear (ht); 57 | perl_destruct (my_perl); 58 | perl_free (my_perl); 59 | 60 | return count; 61 | } 62 | -------------------------------------------------------------------------------- /src/sys-perl/run-perl.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include 5 | #include 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | #include "perl-udb.c" 12 | #include "perl-grow.c" 13 | 14 | 15 | int main (int argc, char * argv []) 16 | { 17 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 18 | } 19 | -------------------------------------------------------------------------------- /src/sys-python/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-python.c 3 | 4 | INCLUDE += `pkg-config --cflags python` 5 | SYSLIBS += `pkg-config --libs python` 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/sys-python/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name python 6 | Module dictionary 7 | Author Guido van Rossum 8 | Description Shared Python runtime library 9 | Download http://python.org 10 | Date 2001, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install libpython-dev 16 | -------------------------------------------------------------------------------- /src/sys-python/python-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | PyObject * ht; 5 | unsigned i; 6 | unsigned count; 7 | 8 | Py_Initialize (); 9 | ht = PyDict_New (); 10 | 11 | for (i = 0; i < n; i ++) 12 | PyDict_SetItem (ht, PyLong_FromUnsignedLong (keys [i]), PyLong_FromUnsignedLong (keys [i])); 13 | 14 | count = PyDict_Size (ht); 15 | 16 | PyDict_Clear (ht); 17 | Py_Finalize (); 18 | 19 | return count; 20 | } 21 | 22 | 23 | unsigned grow_str (unsigned n, char ** keys) 24 | { 25 | PyObject * ht; 26 | unsigned i; 27 | unsigned count; 28 | 29 | Py_Initialize (); 30 | ht = PyDict_New (); 31 | 32 | for (i = 0; i < n; i ++) 33 | PyDict_SetItem (ht, PyString_FromString (keys [i]), PyLong_FromUnsignedLong (i)); 34 | 35 | count = PyDict_Size (ht); 36 | 37 | PyDict_Clear (ht); 38 | Py_Finalize (); 39 | 40 | return count; 41 | } 42 | -------------------------------------------------------------------------------- /src/sys-python/python-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | PyObject * ht; 5 | unsigned i; 6 | unsigned count; 7 | 8 | Py_Initialize (); 9 | ht = PyDict_New (); 10 | 11 | for (i = 0; i < n; i ++) 12 | { 13 | PyObject * hit = PyDict_GetItem (ht, PyLong_FromUnsignedLong (keys [i])); 14 | if (hit) 15 | PyDict_DelItem (ht, PyLong_FromUnsignedLong (keys [i])); 16 | else 17 | PyDict_SetItem (ht, PyLong_FromUnsignedLong (keys [i]), PyLong_FromUnsignedLong (keys [i])); 18 | } 19 | 20 | count = PyDict_Size (ht); 21 | 22 | PyDict_Clear (ht); 23 | Py_Finalize (); 24 | 25 | return count; 26 | } 27 | 28 | 29 | unsigned udb_str (unsigned n, char ** keys) 30 | { 31 | PyObject * ht; 32 | unsigned i; 33 | unsigned count; 34 | 35 | Py_Initialize (); 36 | ht = PyDict_New (); 37 | 38 | for (i = 0; i < n; i ++) 39 | { 40 | PyObject * hit = PyDict_GetItem (ht, PyString_FromString (keys [i])); 41 | if (hit) 42 | PyDict_DelItem (ht, PyString_FromString (keys [i])); 43 | else 44 | PyDict_SetItem (ht, PyString_FromString (keys [i]), PyLong_FromUnsignedLong (i)); 45 | } 46 | 47 | count = PyDict_Size (ht); 48 | 49 | PyDict_Clear (ht); 50 | Py_Finalize (); 51 | 52 | return count; 53 | } 54 | -------------------------------------------------------------------------------- /src/sys-python/run-python.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | #include "python-udb.c" 10 | #include "python-grow.c" 11 | 12 | 13 | int main (int argc, char * argv []) 14 | { 15 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 16 | } 17 | -------------------------------------------------------------------------------- /src/sys-ruby/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-ruby.c 3 | 4 | INCLUDE += `pkg-config --cflags ruby` 5 | SYSLIBS += `pkg-config --libs ruby` 6 | 7 | include ../../etc/Make.rules 8 | -------------------------------------------------------------------------------- /src/sys-ruby/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name ruby 6 | Module hash table 7 | Author Yukihiro Matsumoto (matz@ruby-lang.org) 8 | Description Ruby runtime library 9 | Download http://www.ruby-lang.org 10 | Date 1995, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install libruby 16 | -------------------------------------------------------------------------------- /src/sys-sparsehash/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | C++MAINSRCS = run-sparse.cpp 3 | C++MAINSRCS += run-dense.cpp 4 | 5 | C++FLAGS += -Wno-sign-compare 6 | SYSLIBS += -lstdc++ 7 | 8 | include ../../etc/Make.rules 9 | -------------------------------------------------------------------------------- /src/sys-sparsehash/dense-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | ht -> set_deleted_key (0xfffffffe); 9 | ht -> set_empty_key (0xffffffff); 10 | 11 | for (i = 0; i < n; i ++) 12 | { 13 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 14 | } 15 | 16 | count = ht -> size (); 17 | 18 | delete ht; 19 | 20 | return count; 21 | } 22 | 23 | 24 | unsigned grow_str (unsigned n, char ** keys) 25 | { 26 | hashtable_str_t * ht = new hashtable_str_t; 27 | unsigned i; 28 | unsigned count; 29 | 30 | ht -> set_deleted_key (""); 31 | ht -> set_empty_key ("*"); 32 | 33 | for (i = 0; i < n; i ++) 34 | { 35 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 36 | } 37 | 38 | count = ht -> size (); 39 | 40 | delete ht; 41 | 42 | return count; 43 | } 44 | -------------------------------------------------------------------------------- /src/sys-sparsehash/dense-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | ht -> set_deleted_key (0xfffffffe); 9 | ht -> set_empty_key (0xffffffff); 10 | 11 | for (i = 0; i < n; i ++) 12 | { 13 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 14 | if (hit != ht -> end ()) 15 | ht -> erase (hit -> first); 16 | else 17 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 18 | } 19 | 20 | count = ht -> size (); 21 | 22 | delete ht; 23 | 24 | return count; 25 | } 26 | 27 | 28 | unsigned udb_str (unsigned n, char ** keys) 29 | { 30 | hashtable_str_t * ht = new hashtable_str_t; 31 | unsigned i; 32 | unsigned count; 33 | 34 | ht -> set_deleted_key (""); 35 | ht -> set_empty_key ("*"); 36 | 37 | for (i = 0; i < n; i ++) 38 | { 39 | hashtable_str_t::const_iterator hit = ht -> find (keys [i]); 40 | if (hit != ht -> end ()) 41 | ht -> erase (hit -> first); 42 | else 43 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 44 | } 45 | 46 | count = ht -> size (); 47 | 48 | delete ht; 49 | 50 | return count; 51 | } 52 | -------------------------------------------------------------------------------- /src/sys-sparsehash/run-dense.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include "sparsehash/dense_hash_map" 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | typedef google::dense_hash_map hashtable_int_t; 11 | typedef google::dense_hash_map hashtable_str_t; 12 | 13 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 14 | 15 | #include "dense-udb.cpp" 16 | #include "dense-grow.cpp" 17 | 18 | 19 | int main (int argc, char * argv []) 20 | { 21 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 22 | } 23 | -------------------------------------------------------------------------------- /src/sys-sparsehash/run-sparse.cpp: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "sparsehash/sparse_hash_map" 5 | #include 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | typedef google::sparse_hash_map hashtable_int_t; 10 | typedef google::sparse_hash_map hashtable_str_t; 11 | 12 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 13 | 14 | #include "sparse-udb.cpp" 15 | #include "sparse-grow.cpp" 16 | 17 | 18 | int main (int argc, char * argv []) 19 | { 20 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 21 | } 22 | -------------------------------------------------------------------------------- /src/sys-sparsehash/sparse-grow.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | ht -> set_deleted_key (0xfffffffe); 9 | 10 | for (i = 0; i < n; i ++) 11 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 12 | 13 | count = ht -> size (); 14 | 15 | delete ht; 16 | 17 | return count; 18 | } 19 | 20 | 21 | unsigned grow_str (unsigned n, char ** keys) 22 | { 23 | hashtable_str_t * ht = new hashtable_str_t; 24 | unsigned i; 25 | unsigned count; 26 | 27 | ht -> set_deleted_key (""); 28 | 29 | for (i = 0; i < n; i ++) 30 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 31 | 32 | count = ht -> size (); 33 | 34 | delete ht; 35 | 36 | return count; 37 | } 38 | -------------------------------------------------------------------------------- /src/sys-sparsehash/sparse-udb.cpp: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | hashtable_int_t * ht = new hashtable_int_t; 5 | unsigned i; 6 | unsigned count; 7 | 8 | ht -> set_deleted_key (0xfffffffe); 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | hashtable_int_t::const_iterator hit = ht -> find (keys [i]); 13 | if (hit != ht -> end ()) 14 | ht -> erase (hit -> first); 15 | else 16 | ht -> insert (hashtable_int_t::value_type (keys [i], keys [i])); 17 | } 18 | 19 | count = ht -> size (); 20 | 21 | delete ht; 22 | 23 | return count; 24 | } 25 | 26 | 27 | unsigned udb_str (unsigned n, char ** keys) 28 | { 29 | hashtable_str_t * ht = new hashtable_str_t; 30 | unsigned i; 31 | unsigned count; 32 | 33 | ht -> set_deleted_key (""); 34 | 35 | for (i = 0; i < n; i ++) 36 | { 37 | hashtable_str_t::const_iterator hit = ht -> find (keys [i]); 38 | if (hit != ht -> end ()) 39 | ht -> erase (hit -> first); 40 | else 41 | ht -> insert (hashtable_str_t::value_type (keys [i], i)); 42 | } 43 | 44 | count = ht -> size (); 45 | 46 | delete ht; 47 | 48 | return count; 49 | } 50 | -------------------------------------------------------------------------------- /src/sys-tcl/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-tcl.c 3 | 4 | WFLAGS = -Wno-int-to-pointer-cast 5 | 6 | INCLUDE += -I/usr/include/tcl8.6 7 | SYSLIBS += -ltcl8.6 8 | 9 | include ../../etc/Make.rules 10 | -------------------------------------------------------------------------------- /src/sys-tcl/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name tcl 6 | Module hashtable 7 | Author John Ousterhout 8 | Description Tcl (the Tool Command Language) 9 | Download http://www.tcl.tk 10 | Date 1987, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | sudo apt-get install tcl8.6-dev 16 | -------------------------------------------------------------------------------- /src/sys-tcl/run-tcl.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | 5 | /* The implementation */ 6 | #include 7 | 8 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 9 | 10 | static unsigned Tcl_SizeHashTable (Tcl_HashTable * ht) 11 | { 12 | return ht -> numEntries; 13 | } 14 | 15 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 16 | 17 | #include "tcl-udb.c" 18 | #include "tcl-grow.c" 19 | 20 | 21 | int main (int argc, char * argv []) 22 | { 23 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 24 | } 25 | -------------------------------------------------------------------------------- /src/sys-tcl/tcl-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | Tcl_HashTable * ht = calloc (1, sizeof (* ht)); 5 | unsigned i; 6 | unsigned count; 7 | 8 | Tcl_InitHashTable (ht, TCL_ONE_WORD_KEYS); 9 | 10 | for (i = 0; i < n; i ++) 11 | { 12 | int new_val; 13 | Tcl_HashEntry * he = Tcl_CreateHashEntry (ht, keys [i], & new_val); 14 | Tcl_SetHashValue (he, (ClientData) & keys [i]); 15 | } 16 | 17 | count = Tcl_SizeHashTable (ht); 18 | 19 | Tcl_DeleteHashTable (ht); 20 | free (ht); 21 | 22 | return count; 23 | } 24 | 25 | 26 | unsigned grow_str (unsigned n, char ** keys) 27 | { 28 | Tcl_HashTable * ht = calloc (1, sizeof (* ht)); 29 | unsigned i; 30 | unsigned count; 31 | 32 | Tcl_InitHashTable (ht, TCL_STRING_KEYS); 33 | 34 | for (i = 0; i < n; i ++) 35 | { 36 | int new_val; 37 | Tcl_HashEntry * he = Tcl_CreateHashEntry (ht, keys [i], & new_val); 38 | Tcl_SetHashValue (he, (ClientData) & i); 39 | } 40 | 41 | count = Tcl_SizeHashTable (ht); 42 | 43 | Tcl_DeleteHashTable (ht); 44 | free (ht); 45 | 46 | return count; 47 | } 48 | -------------------------------------------------------------------------------- /src/tommyds/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | SRCS = tommyhash.c 3 | SRCS += tommyhashtbl.c 4 | SRCS += tommyhashlin.c 5 | SRCS += tommyhashdyn.c 6 | LIB = lib-kbench-tommyds.a 7 | MAINSRCS = run-fixed.c 8 | MAINSRCS += run-linear.c 9 | MAINSRCS += run-dynamic.c 10 | 11 | include ../../etc/Make.rules 12 | -------------------------------------------------------------------------------- /src/tommyds/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name tommyds 6 | Module dynamic hash table 7 | Author Andrea Mazzoleni (amadvance@gmail.com) 8 | Description C Hash Table - hash table data structure in C 9 | Download http://github.com/amadvance/tommyds 10 | Date 2010, 2016 11 | Language C 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | - tommytypes.h 18 | - tommylist.h 19 | - tommyhash.h 20 | - tommyhash.c 21 | - tommyhashtbl.h 22 | - tommyhashtbl.c 23 | - tommyhashlin.h 24 | - tommyhashlin.c 25 | - tommyhashdyn.h 26 | - tommyhashdyn.c 27 | -------------------------------------------------------------------------------- /src/tommyds/run-dynamic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | #include "rhash.h" 5 | 6 | /* The implementation */ 7 | #include "tommyhashdyn.h" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | #include "objs.c" 12 | 13 | static tommy_hashdyn * tommy_hashdyn_alloc (void) 14 | { 15 | tommy_hashdyn * ht = calloc (1, sizeof (* ht)); 16 | tommy_hashdyn_init (ht); 17 | return ht; 18 | } 19 | 20 | 21 | static void tommy_hashdyn_free (tommy_hashdyn * ht) 22 | { 23 | tommy_hashdyn_done (ht); 24 | free (ht); 25 | } 26 | 27 | 28 | /* The callback comparison function to look up for matching keys */ 29 | static int cmp_int (const void * key, const void * obj) 30 | { 31 | return * (unsigned *) key == ((obj_t *) obj) -> ukey; 32 | } 33 | 34 | 35 | /* The callback comparison function to look up for matching keys */ 36 | static int cmp_str (const void * key, const void * obj) 37 | { 38 | return strcmp (((obj_t *) key) -> skey, ((obj_t *) obj) -> skey); 39 | } 40 | 41 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 42 | 43 | #include "tommyds-dynamic-udb.c" 44 | #include "tommyds-dynamic-grow.c" 45 | 46 | 47 | int main (int argc, char * argv []) 48 | { 49 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 50 | } 51 | -------------------------------------------------------------------------------- /src/tommyds/run-fixed.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | #include "rhash.h" 5 | 6 | /* The implementation */ 7 | #include "tommyhashtbl.h" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | #include "objs.c" 12 | 13 | static tommy_hashtable * tommy_hashtable_alloc (unsigned n) 14 | { 15 | tommy_hashtable * ht = calloc (1, sizeof (* ht)); 16 | tommy_hashtable_init (ht, n); 17 | return ht; 18 | } 19 | 20 | 21 | static void tommy_hashtable_free (tommy_hashtable * ht) 22 | { 23 | tommy_hashtable_done (ht); 24 | free (ht); 25 | } 26 | 27 | 28 | /* The callback comparison function to look up for matching keys */ 29 | static int cmp_int (const void * key, const void * obj) 30 | { 31 | return * (unsigned *) key == ((obj_t *) obj) -> ukey; 32 | } 33 | 34 | 35 | /* The callback comparison function to look up for matching keys */ 36 | static int cmp_str (const void * key, const void * obj) 37 | { 38 | return strcmp (((obj_t *) key) -> skey, ((obj_t *) obj) -> skey); 39 | } 40 | 41 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 42 | 43 | #include "tommyds-fixed-udb.c" 44 | #include "tommyds-fixed-grow.c" 45 | 46 | 47 | int main (int argc, char * argv []) 48 | { 49 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 50 | } 51 | -------------------------------------------------------------------------------- /src/tommyds/run-linear.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "benchmark.h" 4 | #include "rhash.h" 5 | 6 | /* The implementation */ 7 | #include "tommyhashlin.h" 8 | 9 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 10 | 11 | #include "objs.c" 12 | 13 | static tommy_hashlin * tommy_hashlin_alloc (void) 14 | { 15 | tommy_hashlin * ht = calloc (1, sizeof (* ht)); 16 | tommy_hashlin_init (ht); 17 | return ht; 18 | } 19 | 20 | 21 | static void tommy_hashlin_free (tommy_hashlin * ht) 22 | { 23 | tommy_hashlin_done (ht); 24 | free (ht); 25 | } 26 | 27 | 28 | /* The callback comparison function to look up for matching keys */ 29 | static int cmp_int (const void * key, const void * obj) 30 | { 31 | return * (unsigned *) key == ((obj_t *) obj) -> ukey; 32 | } 33 | 34 | 35 | /* The callback comparison function to look up for matching keys */ 36 | static int cmp_str (const void * key, const void * obj) 37 | { 38 | return strcmp (((obj_t *) key) -> skey, ((obj_t *) obj) -> skey); 39 | } 40 | 41 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 42 | 43 | #include "tommyds-linear-udb.c" 44 | #include "tommyds-linear-grow.c" 45 | 46 | 47 | int main (int argc, char * argv []) 48 | { 49 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 50 | } 51 | -------------------------------------------------------------------------------- /src/tommyds/tommyds-dynamic-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t ** objs = setup_int_objs (n, keys); 5 | tommy_hashdyn * ht = tommy_hashdyn_alloc (); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | tommy_hashdyn_insert (ht, & objs [i] -> _reserved_, objs [i], tommy_inthash_u32 (objs [i] -> ukey)); 11 | 12 | count = tommy_hashdyn_count (ht); 13 | 14 | tommy_hashdyn_free (ht); 15 | teardown (n, objs); 16 | 17 | return count; 18 | } 19 | 20 | 21 | unsigned grow_str (unsigned n, char ** keys) 22 | { 23 | obj_t ** objs = setup_str_objs (n, keys); 24 | tommy_hashdyn * ht = tommy_hashdyn_alloc (); 25 | unsigned i; 26 | unsigned count; 27 | 28 | for (i = 0; i < n; i ++) 29 | tommy_hashdyn_insert (ht, & objs [i] -> _reserved_, objs [i], tommy_hash_u64 (0, objs [i] -> skey, strlen (objs [i] -> skey))); 30 | 31 | count = tommy_hashdyn_count (ht); 32 | 33 | tommy_hashdyn_free (ht); 34 | teardown (n, objs); 35 | 36 | return count; 37 | } 38 | -------------------------------------------------------------------------------- /src/tommyds/tommyds-dynamic-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t ** objs = setup_int_objs (n, keys); 5 | tommy_hashdyn * ht = tommy_hashdyn_alloc (); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | unsigned key = java_hash (objs [i] -> ukey); 12 | if (tommy_hashdyn_search (ht, cmp_int, objs [i], key)) 13 | tommy_hashdyn_remove (ht, cmp_int, objs [i], key); 14 | else 15 | tommy_hashdyn_insert (ht, & objs [i] -> _reserved_, objs [i], key); 16 | } 17 | 18 | count = tommy_hashdyn_count (ht); 19 | 20 | tommy_hashdyn_free (ht); 21 | teardown (n, objs); 22 | 23 | return count; 24 | } 25 | 26 | 27 | unsigned udb_str (unsigned n, char ** keys) 28 | { 29 | obj_t ** objs = setup_str_objs (n, keys); 30 | tommy_hashdyn * ht = tommy_hashdyn_alloc (); 31 | unsigned i; 32 | unsigned count; 33 | 34 | for (i = 0; i < n; i ++) 35 | { 36 | unsigned key = python_hash (objs [i] -> skey); 37 | if (tommy_hashdyn_search (ht, cmp_str, objs [i], key)) 38 | tommy_hashdyn_remove (ht, cmp_str, objs [i], key); 39 | else 40 | tommy_hashdyn_insert (ht, & objs [i] -> _reserved_, objs [i], key); 41 | } 42 | 43 | count = tommy_hashdyn_count (ht); 44 | 45 | tommy_hashdyn_free (ht); 46 | teardown (n, objs); 47 | 48 | return count; 49 | } 50 | -------------------------------------------------------------------------------- /src/tommyds/tommyds-fixed-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t ** objs = setup_int_objs (n, keys); 5 | tommy_hashtable * ht = tommy_hashtable_alloc (n); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | tommy_hashtable_insert (ht, & objs [i] -> _reserved_, objs [i], tommy_inthash_u64 (objs [i] -> ukey)); 11 | 12 | count = tommy_hashtable_count (ht); 13 | 14 | tommy_hashtable_free (ht); 15 | teardown (n, objs); 16 | 17 | return count; 18 | } 19 | 20 | 21 | unsigned grow_str (unsigned n, char ** keys) 22 | { 23 | obj_t ** objs = setup_str_objs (n, keys); 24 | tommy_hashtable * ht = tommy_hashtable_alloc (n); 25 | unsigned i; 26 | unsigned count; 27 | 28 | for (i = 0; i < n; i ++) 29 | tommy_hashtable_insert (ht, & objs [i] -> _reserved_, objs [i], tommy_hash_u64 (0, objs [i] -> skey, strlen (objs [i] -> skey))); 30 | 31 | count = tommy_hashtable_count (ht); 32 | 33 | tommy_hashtable_free (ht); 34 | teardown (n, objs); 35 | 36 | return count; 37 | } 38 | -------------------------------------------------------------------------------- /src/tommyds/tommyds-linear-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t ** objs = setup_int_objs (n, keys); 5 | tommy_hashlin * ht = tommy_hashlin_alloc (); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | tommy_hashlin_insert (ht, & objs [i] -> _reserved_, objs [i], tommy_inthash_u64 (objs [i] -> ukey)); 11 | 12 | count = tommy_hashlin_count (ht); 13 | 14 | tommy_hashlin_free (ht); 15 | teardown (n, objs); 16 | 17 | return count; 18 | } 19 | 20 | 21 | unsigned grow_str (unsigned n, char ** keys) 22 | { 23 | obj_t ** objs = setup_str_objs (n, keys); 24 | tommy_hashlin * ht = tommy_hashlin_alloc (); 25 | unsigned i; 26 | unsigned count; 27 | 28 | for (i = 0; i < n; i ++) 29 | tommy_hashlin_insert (ht, & objs [i] -> _reserved_, objs [i], tommy_hash_u64 (0, objs [i] -> skey, strlen (objs [i] -> skey))); 30 | 31 | count = tommy_hashlin_count (ht); 32 | 33 | tommy_hashlin_free (ht); 34 | teardown (n, objs); 35 | 36 | return count; 37 | } 38 | -------------------------------------------------------------------------------- /src/tommyds/tommyds-linear-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | obj_t ** objs = setup_int_objs (n, keys); 5 | tommy_hashlin * ht = tommy_hashlin_alloc (); 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | unsigned key = java_hash (objs [i] -> ukey); 12 | if (tommy_hashlin_search (ht, cmp_int, objs [i], key)) 13 | tommy_hashlin_remove (ht, cmp_int, objs [i], key); 14 | else 15 | tommy_hashlin_insert (ht, & objs [i] -> _reserved_, objs [i], key); 16 | } 17 | 18 | count = tommy_hashlin_count (ht); 19 | 20 | tommy_hashlin_free (ht); 21 | teardown (n, objs); 22 | 23 | return count; 24 | } 25 | 26 | 27 | unsigned udb_str (unsigned n, char ** keys) 28 | { 29 | obj_t ** objs = setup_str_objs (n, keys); 30 | tommy_hashlin * ht = tommy_hashlin_alloc (); 31 | unsigned i; 32 | unsigned count; 33 | 34 | for (i = 0; i < n; i ++) 35 | { 36 | unsigned key = python_hash (objs [i] -> skey); 37 | if (tommy_hashlin_search (ht, cmp_str, objs [i], key)) 38 | tommy_hashlin_remove (ht, cmp_str, objs [i], key); 39 | else 40 | tommy_hashlin_insert (ht, & objs [i] -> _reserved_, objs [i], key); 41 | } 42 | 43 | count = tommy_hashlin_count (ht); 44 | 45 | tommy_hashlin_free (ht); 46 | teardown (n, objs); 47 | 48 | return count; 49 | } 50 | -------------------------------------------------------------------------------- /src/ulib/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-ulib-open.c 3 | 4 | include ../../etc/Make.rules 5 | -------------------------------------------------------------------------------- /src/ulib/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name ulib 6 | Module ulib 7 | Author Zilong Tan (eric.zltan@gmail.com) 8 | Description The ULIB is an efficient algorithm library for C and C++ (based on khash) 9 | Download http://github.com/ZilongTan/Coding/ulib 10 | Date 2011, 2013 11 | Language C macro 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were locally copied from latest git version: 17 | 18 | - hash_open_prot.h 19 | - hash_chain_prot.h 20 | - util_algo.h 21 | -------------------------------------------------------------------------------- /src/ulib/run-ulib-open.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "hash_open_prot.h" 5 | #include "rhash.h" 6 | 7 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 8 | 9 | #define OPENHASH_ISMAP 1 10 | #define OPENHASH_ISSET 0 11 | 12 | /* identity hash function to convert an integer key to an integer */ 13 | static int hash_int_fn (unsigned key) 14 | { 15 | return openhash_hashfn (key); 16 | } 17 | 18 | 19 | /* boolean function that tests whether two keys are equal */ 20 | static int eq_int_fn (unsigned k1, unsigned k2) 21 | { 22 | return openhash_equalfn (k1, k2); 23 | } 24 | 25 | 26 | static int hash_str_fn (char * key) 27 | { 28 | return python_hash (key); 29 | } 30 | 31 | 32 | static int eq_str_fn (char * k1, char * k2) 33 | { 34 | return ! strcmp (k1, k2); 35 | } 36 | 37 | 38 | /* Generates typedef for hash table and inline functions */ 39 | DEFINE_OPENHASH (uht_t, unsigned, unsigned, OPENHASH_ISMAP, hash_int_fn, eq_int_fn) 40 | DEFINE_OPENHASH (sht_t, char *, unsigned, OPENHASH_ISMAP, hash_str_fn, eq_str_fn) 41 | 42 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 43 | #include "ulib-open-udb.c" 44 | #include "ulib-open-grow.c" 45 | 46 | 47 | int main (int argc, char * argv []) 48 | { 49 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 50 | } 51 | -------------------------------------------------------------------------------- /src/ulib/ulib-open-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | openhash_t(uht_t) * ht = openhash_init (uht_t); 5 | unsigned i; 6 | int ret; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | oh_iter_t hi = openhash_set (uht_t, ht, keys [i], & ret); 12 | openhash_value (ht, hi) = keys [i]; 13 | } 14 | 15 | count = openhash_size (ht); 16 | 17 | openhash_destroy (uht_t, ht); 18 | 19 | return count; 20 | } 21 | 22 | 23 | unsigned grow_str (unsigned n, char ** keys) 24 | { 25 | openhash_t(sht_t) * ht = openhash_init (sht_t); 26 | unsigned i; 27 | unsigned count; 28 | 29 | for (i = 0; i < n; i ++) 30 | { 31 | oh_iter_t hi = openhash_get (sht_t, ht, keys [i]); 32 | if (hi != openhash_end (ht)) 33 | openhash_del (sht_t, ht, hi); 34 | else 35 | { 36 | int ret; 37 | hi = openhash_set (sht_t, ht, keys [i], & ret); 38 | openhash_value (ht, hi) = i; 39 | } 40 | } 41 | 42 | count = openhash_size (ht); 43 | 44 | openhash_destroy (sht_t, ht); 45 | 46 | return count; 47 | } 48 | -------------------------------------------------------------------------------- /src/ulib/ulib-open-udb.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned udb_int (unsigned n, unsigned * keys) 3 | { 4 | openhash_t(uht_t) * ht = openhash_init (uht_t); 5 | unsigned i; 6 | unsigned count; 7 | 8 | for (i = 0; i < n; i ++) 9 | { 10 | oh_iter_t hi = openhash_get (uht_t, ht, keys [i]); 11 | if (hi != openhash_end (ht)) 12 | openhash_del (uht_t, ht, hi); 13 | else 14 | { 15 | int ret; 16 | hi = openhash_set (uht_t, ht, keys [i], & ret); 17 | openhash_value (ht, hi) = keys [i]; 18 | } 19 | } 20 | 21 | count = openhash_size (ht); 22 | 23 | openhash_destroy (uht_t, ht); 24 | 25 | return count; 26 | } 27 | 28 | 29 | unsigned udb_str (unsigned n, char ** keys) 30 | { 31 | openhash_t(sht_t) * ht = openhash_init (sht_t); 32 | unsigned i; 33 | unsigned count; 34 | 35 | for (i = 0; i < n; i ++) 36 | { 37 | oh_iter_t hi = openhash_get (sht_t, ht, keys [i]); 38 | if (hi != openhash_end (ht)) 39 | openhash_del (sht_t, ht, hi); 40 | else 41 | { 42 | int ret; 43 | hi = openhash_set (sht_t, ht, keys [i], & ret); 44 | openhash_value (ht, hi) = i; 45 | } 46 | } 47 | 48 | count = openhash_size (ht); 49 | 50 | openhash_destroy (sht_t, ht); 51 | 52 | return count; 53 | } 54 | -------------------------------------------------------------------------------- /src/uthash/Makefile: -------------------------------------------------------------------------------- 1 | # The name of the games 2 | MAINSRCS = run-uthash.c 3 | 4 | include ../../etc/Make.rules 5 | -------------------------------------------------------------------------------- /src/uthash/README: -------------------------------------------------------------------------------- 1 | Rocco Carbone (rocco@tecsiel.it) 2 | Pisa, Aug 2016 3 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 4 | 5 | Name uthash 6 | Module hash table 7 | Author Troy D. Hanson () 8 | Description C macros for hash tables and more 9 | Download http://github.com/troydhanson/uthash 10 | Date 2003, 2016 11 | Language C macro 12 | 13 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 14 | 15 | 16 | The following sources files were copied from latest git version: 17 | 18 | - uthash.h 19 | 20 | No modification was needed. 21 | -------------------------------------------------------------------------------- /src/uthash/run-uthash.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | /* The implementation */ 4 | #include "uthash.h" 5 | 6 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 7 | 8 | typedef struct ht ht_t; 9 | struct ht 10 | { 11 | unsigned key; 12 | char str [16]; 13 | unsigned val; 14 | 15 | UT_hash_handle hh; /* field must be named hh in order to use the convenience macros */ 16 | }; 17 | 18 | /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */ 19 | 20 | #include "uthash-udb.c" 21 | #include "uthash-grow.c" 22 | 23 | 24 | int main (int argc, char * argv []) 25 | { 26 | return udb_benchmark (argc, argv, udb_int, udb_str, grow_int, grow_str); 27 | } 28 | -------------------------------------------------------------------------------- /src/uthash/uthash-grow.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned grow_int (unsigned n, unsigned * keys) 3 | { 4 | ht_t * items = calloc (n, sizeof (ht_t)); 5 | ht_t * ht = NULL; /* important! initialize to NULL */ 6 | unsigned i; 7 | unsigned count; 8 | 9 | for (i = 0; i < n; i ++) 10 | { 11 | items [i] . key = keys [i]; 12 | items [i] . val = i; 13 | } 14 | 15 | for (i = 0; i < n; i ++) 16 | HASH_ADD_INT (ht, key, & items [i]); 17 | 18 | count = HASH_COUNT (ht); 19 | 20 | HASH_CLEAR (hh, ht); 21 | free (items); 22 | 23 | return count; 24 | } 25 | 26 | 27 | unsigned grow_str (unsigned n, char ** keys) 28 | { 29 | ht_t * items = calloc (n, sizeof (ht_t)); 30 | ht_t * ht = NULL; /* important! initialize to NULL */ 31 | unsigned i; 32 | unsigned count; 33 | 34 | for (i = 0; i < n; i ++) 35 | { 36 | strcpy (items [i] . str, keys [i]); 37 | items [i] . key = i; 38 | } 39 | 40 | for (i = 0; i < n; i ++) 41 | HASH_ADD_KEYPTR (hh, ht, items [i] . str, strlen (items [i] . str), & items [i]); 42 | 43 | count = HASH_COUNT (ht); 44 | 45 | HASH_CLEAR (hh, ht); 46 | free (items); 47 | 48 | return count; 49 | } 50 | --------------------------------------------------------------------------------