├── src ├── GM_avl │ ├── fail │ └── avltest.cpp ├── stlavlmap │ └── fail ├── rdestl │ ├── rdestl │ │ ├── string.h │ │ ├── slist.cpp │ │ ├── list.cpp │ │ ├── int_to_type.h │ │ ├── allocator.h │ │ ├── fixed_sorted_vector.h │ │ ├── allocator.cpp │ │ ├── intrusive_slist.cpp │ │ ├── functional.h │ │ ├── intrusive_list.cpp │ │ ├── LICENSE │ │ ├── buffer_allocator.h │ │ ├── string_utils.h │ │ ├── pair.h │ │ ├── rdestl.h │ │ ├── fixed_array.h │ │ ├── fixed_substring.h │ │ ├── stack.h │ │ ├── type_traits.h │ │ ├── iterator.h │ │ ├── set.h │ │ ├── simple_string_storage.h │ │ ├── sorted_vector.h │ │ ├── intrusive_list.h │ │ └── fixed_vector.h │ ├── Makefile.ORG │ ├── Makefile │ ├── test.cc │ └── new.h ├── benchmark │ ├── benchmark.h │ ├── Makefile │ ├── Makefile.ORG │ ├── benchmark.c │ └── benchmark.c.ORG ├── runit │ ├── runtest.c │ ├── Makefile.ORG │ ├── Makefile │ └── runlib.h ├── sglib_rbtree │ ├── Makefile.ORG │ ├── Makefile │ └── test.c ├── htable │ ├── Makefile.ORG │ ├── Makefile │ ├── test.c.ORG │ └── test.c ├── JE_rb_new │ ├── Makefile │ └── test.c ├── JE_rb_old │ ├── Makefile │ └── test.c ├── khash │ ├── Makefile │ └── test.c ├── JE_trp_hash │ ├── Makefile.ORG │ ├── Makefile │ └── test.c ├── JE_trp_prng │ ├── Makefile.ORG │ ├── Makefile │ └── test.c ├── NP_rbtree │ ├── Makefile.ORG │ ├── Makefile │ └── test.c ├── NP_splaytree │ ├── Makefile │ └── test.c ├── kbtree │ ├── Makefile │ └── test.c ├── stb_hash │ ├── Makefile.ORG │ ├── Makefile │ ├── test.c.ORG │ └── test.c ├── libavl_avl │ ├── Makefile │ ├── test.c │ └── avl.h ├── libavl_bst │ ├── Makefile │ ├── test.c │ └── bst.h ├── libavl_prb │ ├── Makefile │ ├── test.c │ └── prb.h ├── libavl_rb │ ├── Makefile │ ├── test.c │ └── rb.h ├── JG_btree │ ├── Makefile │ ├── test.c │ ├── btreepriv.h.ORG │ ├── btreepriv.h │ └── btree.h ├── uthash │ ├── Makefile │ └── test.c ├── _gdsl_rb │ ├── Makefile.ORG │ ├── Makefile │ ├── test.c.ORG │ └── test.c ├── _glib_hash │ ├── Makefile │ ├── test.c.ORG │ └── test.c ├── _glib_tree │ ├── Makefile │ ├── test.c.ORG │ └── test.c ├── TN_rbtree │ ├── Makefile.ORG │ ├── Makefile │ └── test.cc ├── sgi_hash_map │ ├── Makefile.ORG │ ├── Makefile │ ├── test.cc.ORG │ └── test.cc ├── tr1_unordered_map │ ├── Makefile │ ├── test.cc.ORG │ └── test.cc ├── google_sparse │ ├── Makefile.ORG │ ├── Makefile │ ├── test.cc │ ├── test.cc.ORG │ └── google │ │ └── sparsehash │ │ └── sparseconfig.h ├── libavl_rb_cpp │ ├── Makefile │ ├── test.cc │ └── test.cc.ORG ├── _boost_hash │ ├── Makefile │ └── test.cc ├── libavl_avl_cpp │ ├── Makefile │ ├── test.cc │ └── test.cc.ORG ├── libavl_rb_cpp2 │ ├── Makefile │ ├── test.cc │ └── test.cc.ORG ├── _qt_qhash │ ├── Makefile.ORG │ ├── Makefile │ └── test.cc ├── _qt_qmap │ ├── Makefile.ORG │ ├── Makefile │ └── test.cc ├── google_dense │ ├── Makefile │ ├── test.cc.ORG │ ├── test.cc │ └── google │ │ └── sparsehash │ │ └── sparseconfig.h ├── sgi_map │ ├── Makefile │ ├── test.cc.ORG │ ├── test.cc │ └── test2.cc ├── stx_btree │ ├── Makefile │ ├── stx │ │ ├── btree │ │ ├── btree_map │ │ ├── btree_set │ │ ├── btree_multimap │ │ └── btree_multiset │ ├── test.cc.ORG │ └── test.cc ├── Makefile.ORG ├── Makefile └── README ├── etc ├── udb.pdf └── udb.numbers ├── .gitignore ├── Makefile └── README.md /src/GM_avl/fail: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/stlavlmap/fail: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /etc/udb.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcarbone/kudb/HEAD/etc/udb.pdf -------------------------------------------------------------------------------- /etc/udb.numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcarbone/kudb/HEAD/etc/udb.numbers -------------------------------------------------------------------------------- /src/rdestl/rdestl/string.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_CORE_H 2 | #define RDESTL_CORE_H 3 | 4 | #include "rdestl/basic_string.h" 5 | 6 | namespace rde 7 | { 8 | typedef basic_string string; 9 | } 10 | 11 | #endif // RDESTL_CORE_H 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Libraries 2 | *.a 3 | 4 | # Shared objects 5 | *.so 6 | 7 | # Object files 8 | *.o 9 | 10 | # Dependency files 11 | *.M 12 | 13 | # Backup files 14 | *~ 15 | 16 | # Executables 17 | src/*/test 18 | src/benchmark/run 19 | src/runit/runit 20 | src/runit/runtest 21 | -------------------------------------------------------------------------------- /src/benchmark/benchmark.h: -------------------------------------------------------------------------------- 1 | #ifndef UDB_BENCHMARK_H 2 | #define UDB_BENCHMARK_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int udb_benchmark(int argc, char *argv[], int (*func_int)(int, const unsigned*), int (*func)(int, char *const*)); 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/runit/runtest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define TIME 10 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | int i; 9 | for (i = 0; i != TIME; ++i) { 10 | fprintf(stdout, "-- stdout: %d\n", i); 11 | fprintf(stderr, "-- stderr: %d\n", i); 12 | sleep(1); 13 | } 14 | fprintf(stdout, "-- stdout: END\n"); 15 | fprintf(stderr, "-- stderr: END\n"); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/benchmark/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= benchmark.o ../runit/runlib.o ../runit/runit.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= -lpthread 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | run:$(OBJS) 14 | $(CC) -o $@ $(OBJS) $(LIBS) 15 | 16 | cleanlocal: 17 | rm -f *.o a.out *~ run 18 | 19 | clean:cleanlocal 20 | 21 | -------------------------------------------------------------------------------- /src/benchmark/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o khtest.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | run:$(OBJS) 14 | $(CC) -o $@ $(OBJS) $(LIBS) 15 | 16 | cleanlocal: 17 | rm -f *.o a.out *~ run 18 | 19 | clean:cleanlocal 20 | 21 | -------------------------------------------------------------------------------- /src/sglib_rbtree/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | 23 | -------------------------------------------------------------------------------- /src/htable/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | -------------------------------------------------------------------------------- /src/JE_rb_new/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/JE_rb_old/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/khash/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | 23 | -------------------------------------------------------------------------------- /src/JE_trp_hash/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/JE_trp_prng/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/NP_rbtree/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/NP_splaytree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/kbtree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o:kbtree.h 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/stb_hash/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | 23 | -------------------------------------------------------------------------------- /src/libavl_avl/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o avl.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit -I. 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/libavl_bst/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o bst.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit -I. 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/libavl_prb/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o prb.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit -I. 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/libavl_rb/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o rb.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit -I. 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/JG_btree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o bt_code.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit -I. 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/NP_rbtree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -Wno-unused-function 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/JE_trp_hash/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -Wno-unused-function 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/JE_trp_prng/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -Wno-unused-function 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/uthash/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= -DHASH_FUNCTION=HASH_BER 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | 23 | -------------------------------------------------------------------------------- /src/htable/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer -Wno-pointer-sign -Wno-unused-function 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | -------------------------------------------------------------------------------- /src/runit/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | DFLAGS= 4 | OBJS= runit.o runlib.o 5 | PROG= runit runtest 6 | VERSION= 0.1.0 7 | LIBS= -lpthread 8 | 9 | .SUFFIXES:.c .o 10 | 11 | .c.o: 12 | $(CC) -c $(CFLAGS) $(DFLAGS) $< -o $@ 13 | 14 | all:$(PROG) 15 | 16 | runit:$(OBJS) 17 | $(CC) $(CFLAGS) $(DFLAGS) $(OBJS) -o $@ $(LIBS) 18 | 19 | runtest:runtest.o 20 | $(CC) $(CFLAGS) runtest.o -o $@ 21 | 22 | cleanlocal: 23 | rm -f *.o a.out *~ *.a $(PROG) $(MANPAGE) 24 | 25 | clean:cleanlocal -------------------------------------------------------------------------------- /src/runit/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -Wno-format 3 | DFLAGS= 4 | OBJS= runit.o runlib.o 5 | PROG= runit runtest 6 | VERSION= 0.1.0 7 | LIBS= -lpthread 8 | 9 | .SUFFIXES:.c .o 10 | 11 | .c.o: 12 | $(CC) -c $(CFLAGS) $(DFLAGS) $< -o $@ 13 | 14 | all:$(PROG) 15 | 16 | runit:$(OBJS) 17 | $(CC) $(CFLAGS) $(DFLAGS) $(OBJS) -o $@ $(LIBS) 18 | 19 | runtest:runtest.o 20 | $(CC) $(CFLAGS) runtest.o -o $@ 21 | 22 | cleanlocal: 23 | rm -f *.o a.out *~ *.a $(PROG) $(MANPAGE) 24 | 25 | clean:cleanlocal 26 | -------------------------------------------------------------------------------- /src/_gdsl_rb/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit -I. -I$(HOME)/opt/include 6 | LIBS= -L$(HOME)/opt/lib -lgdsl 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | test.o: 19 | 20 | cleanlocal: 21 | rm -f *.o a.out *~ test 22 | 23 | clean:cleanlocal 24 | 25 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/slist.cpp: -------------------------------------------------------------------------------- 1 | #include "rdestl/slist.h" 2 | 3 | namespace rde 4 | { 5 | namespace internal 6 | { 7 | void slist_base_node::link_after(slist_base_node* prevNode) 8 | { 9 | RDE_ASSERT(!in_list()); 10 | next = prevNode->next; 11 | prevNode->next = this; 12 | } 13 | void slist_base_node::unlink(slist_base_node* prevNode) 14 | { 15 | RDE_ASSERT(in_list()); 16 | RDE_ASSERT(prevNode->next == this); 17 | prevNode->next = next; 18 | next = this; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/_glib_hash/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit `pkg-config --cflags glib-2.0` 6 | LIBS= `pkg-config --libs glib-2.0` 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | 23 | -------------------------------------------------------------------------------- /src/_glib_tree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit `pkg-config --cflags glib-2.0` 6 | LIBS= `pkg-config --libs glib-2.0` 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | 23 | -------------------------------------------------------------------------------- /src/sglib_rbtree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -Wno-unused-but-set-variable -Wno-implicit-function-declaration -Wno-unused-variable 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | INCLUDES= -I../benchmark -I../runit 6 | LIBS= 7 | 8 | .SUFFIXES:.c .o 9 | 10 | .c.o: 11 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 12 | 13 | all:test 14 | 15 | test:$(OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 17 | 18 | cleanlocal: 19 | rm -f *.o a.out *~ test 20 | 21 | clean:cleanlocal 22 | 23 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/list.cpp: -------------------------------------------------------------------------------- 1 | #include "rdestl/list.h" 2 | 3 | namespace rde 4 | { 5 | namespace internal 6 | { 7 | void list_base_node::link_before(list_base_node* nextNode) 8 | { 9 | RDE_ASSERT(!in_list()); 10 | prev = nextNode->prev; 11 | prev->next = this; 12 | nextNode->prev = this; 13 | next = nextNode; 14 | } 15 | void list_base_node::unlink() 16 | { 17 | RDE_ASSERT(in_list()); 18 | prev->next = next; 19 | next->prev = prev; 20 | next = prev = this; 21 | } 22 | } // internal 23 | } 24 | -------------------------------------------------------------------------------- /src/TN_rbtree/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/sgi_hash_map/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/tr1_unordered_map/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/TN_rbtree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer -Wno-format 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/google_sparse/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit -I. 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/rdestl/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/sgi_hash_map/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer -Wno-deprecated 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/libavl_rb_cpp/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | DFLAGS= 5 | CXXFLAGS= $(CFLAGS) 6 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 7 | INCLUDES= -I../benchmark -I../runit -I. 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | test.o: 24 | 25 | cleanlocal: 26 | rm -f *.o a.out *~ test 27 | 28 | clean:cleanlocal 29 | 30 | -------------------------------------------------------------------------------- /src/_boost_hash/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit -I$(HOME)/opt/x86_64-linux/include 8 | LIBS= 9 | 10 | .SUFFIXES:.c .cc .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | .cc.o: 15 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 16 | 17 | all:test 18 | 19 | test:$(OBJS) 20 | $(CXX) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 21 | 22 | cleanlocal: 23 | rm -f *.o a.out *~ test 24 | 25 | clean:cleanlocal 26 | 27 | -------------------------------------------------------------------------------- /src/libavl_avl_cpp/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | DFLAGS= 5 | CXXFLAGS= $(CFLAGS) 6 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 7 | INCLUDES= -I../benchmark -I../runit -I. 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | test.o: 24 | 25 | cleanlocal: 26 | rm -f *.o a.out *~ test 27 | 28 | clean:cleanlocal 29 | 30 | -------------------------------------------------------------------------------- /src/libavl_rb_cpp2/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | DFLAGS= 5 | CXXFLAGS= $(CFLAGS) 6 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 7 | INCLUDES= -I../benchmark -I../runit -I. 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | test.o: 24 | 25 | cleanlocal: 26 | rm -f *.o a.out *~ test 27 | 28 | clean:cleanlocal 29 | 30 | -------------------------------------------------------------------------------- /src/_qt_qhash/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit -I$(HOME)/opt/x86_64-linux/include 8 | LIBS= -L$(HOME)/opt/x86_64-linux/lib -lQtCore 9 | 10 | .SUFFIXES:.c .cc .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | .cc.o: 15 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 16 | 17 | all:test 18 | 19 | test:$(OBJS) 20 | $(CXX) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 21 | 22 | cleanlocal: 23 | rm -f *.o a.out *~ test 24 | 25 | clean:cleanlocal 26 | 27 | -------------------------------------------------------------------------------- /src/_qt_qmap/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit -I$(HOME)/opt/x86_64-linux/include 8 | LIBS= -L$(HOME)/opt/x86_64-linux/lib -lQtCore 9 | 10 | .SUFFIXES:.c .cc .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | .cc.o: 15 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 16 | 17 | all:test 18 | 19 | test:$(OBJS) 20 | $(CXX) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 21 | 22 | cleanlocal: 23 | rm -f *.o a.out *~ test 24 | 25 | clean:cleanlocal 26 | 27 | -------------------------------------------------------------------------------- /src/_qt_qhash/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit -I/usr/include/qt4 8 | # LIBS= -L$(HOME)/opt/x86_64-linux/lib -lQtCore 9 | LIBS= -lQtCore 10 | 11 | .SUFFIXES:.c .cc .o 12 | 13 | .c.o: 14 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/_qt_qmap/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit -I/usr/include/qt4 8 | # LIBS= -L$(HOME)/opt/x86_64-linux/lib -lQtCore 9 | LIBS= -lQtCore 10 | 11 | .SUFFIXES:.c .cc .o 12 | 13 | .c.o: 14 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | cleanlocal: 24 | rm -f *.o a.out *~ test 25 | 26 | clean:cleanlocal 27 | 28 | -------------------------------------------------------------------------------- /src/google_dense/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | # INCLUDES= -I../benchmark -I../runit -I. 8 | INCLUDES= -I../benchmark -I../runit -I/home/rocco/git/containers/sparsehash/src 9 | LIBS= 10 | 11 | .SUFFIXES:.c .o 12 | 13 | .c.o: 14 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 15 | 16 | .cc.o: 17 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 18 | 19 | all:test 20 | 21 | test:$(OBJS) 22 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 23 | 24 | cleanlocal: 25 | rm -f *.o a.out *~ test 26 | 27 | clean:cleanlocal 28 | 29 | -------------------------------------------------------------------------------- /src/google_sparse/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | # INCLUDES= -I../benchmark -I../runit -I. 8 | INCLUDES= -I../benchmark -I../runit -I/home/rocco/git/containers/sparsehash/src 9 | LIBS= 10 | 11 | .SUFFIXES:.c .o 12 | 13 | .c.o: 14 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 15 | 16 | .cc.o: 17 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 18 | 19 | all:test 20 | 21 | test:$(OBJS) 22 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 23 | 24 | cleanlocal: 25 | rm -f *.o a.out *~ test 26 | 27 | clean:cleanlocal 28 | 29 | -------------------------------------------------------------------------------- /src/_gdsl_rb/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fno-diagnostics-color 3 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 4 | DFLAGS= 5 | # INCLUDES= -I../benchmark -I../runit -I. -I$(HOME)/opt/include 6 | INCLUDES= -I../benchmark -I../runit -I. -I/home/rocco/git/containers/gdsl-1.8 -I/home/rocco/git/containers/gdsl-1.8/src 7 | # LIBS= -L$(HOME)/opt/lib -lgdsl 8 | LIBS= /home/rocco/git/containers/gdsl-1.8/src/.libs/libgdsl.a 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | all:test 16 | 17 | test:$(OBJS) 18 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 19 | 20 | test.o: 21 | 22 | cleanlocal: 23 | rm -f *.o a.out *~ test 24 | 25 | clean:cleanlocal 26 | 27 | -------------------------------------------------------------------------------- /src/sgi_map/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | test2:../benchmark/benchmark.o ../runit/runlib.o test2.o 24 | $(CXX) $(CXXFLAGS) -o $@ ../benchmark/benchmark.o ../runit/runlib.o test2.o $(LIBS) 25 | 26 | cleanlocal: 27 | rm -f *.o a.out *~ test test2 28 | 29 | clean:cleanlocal 30 | 31 | -------------------------------------------------------------------------------- /src/stb_hash/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer -Wno-unused-variable -Wno-unused-function -Wno-unused-value -Wno-parentheses -Wno-implicit-int -Wno-return-type 3 | CFLAGS += -Wno-strict-aliasing -Wno-pointer-to-int-cast -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types 4 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 5 | DFLAGS= 6 | INCLUDES= -I../benchmark -I../runit 7 | LIBS= -lm 8 | 9 | .SUFFIXES:.c .o 10 | 11 | .c.o: 12 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 13 | 14 | all:test 15 | 16 | test:$(OBJS) 17 | $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) 18 | 19 | cleanlocal: 20 | rm -f *.o a.out *~ test 21 | 22 | clean:cleanlocal 23 | 24 | -------------------------------------------------------------------------------- /src/stx_btree/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o 6 | DFLAGS= 7 | INCLUDES= -I../benchmark -I../runit -I. 8 | LIBS= 9 | 10 | .SUFFIXES:.c .o 11 | 12 | .c.o: 13 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 14 | 15 | .cc.o: 16 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 17 | 18 | all:test 19 | 20 | test:$(OBJS) 21 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 22 | 23 | test2:../benchmark/benchmark.o ../runit/runlib.o test2.o 24 | $(CXX) $(CXXFLAGS) -o $@ ../benchmark/benchmark.o ../runit/runlib.o test2.o $(LIBS) 25 | 26 | cleanlocal: 27 | rm -f *.o a.out *~ test test2 28 | 29 | clean:cleanlocal 30 | 31 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/allocator.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_ALLOCATOR_H 2 | #define RDESTL_ALLOCATOR_H 3 | 4 | #include 5 | 6 | namespace rde 7 | { 8 | 9 | // CONCEPT! 10 | class allocator 11 | { 12 | public: 13 | explicit allocator(const char* name = "DEFAULT"): m_name(name) {} 14 | ~allocator() {} 15 | 16 | void* allocate(size_t bytes, int flags = 0); 17 | void* allocate_aligned(size_t bytes, size_t alignment, int flags = 0); 18 | void deallocate(void* ptr, size_t bytes); 19 | 20 | const char* get_name() const; 21 | 22 | private: 23 | const char* m_name; 24 | }; 25 | 26 | } // namespace rde 27 | 28 | //----------------------------------------------------------------------------- 29 | #endif // #ifndef RDESTL_ALLOCATOR_H 30 | -------------------------------------------------------------------------------- /src/rdestl/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o \ 6 | rdestl/allocator.o rdestl/intrusive_list.o \ 7 | rdestl/list.o rdestl/slist.o 8 | DFLAGS= 9 | INCLUDES= -I../benchmark -I../runit -I. 10 | LIBS= 11 | 12 | .SUFFIXES:.c .o .cc .cpp 13 | 14 | .c.o: 15 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 16 | 17 | .cc.o: 18 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 19 | 20 | .cpp.o: 21 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 22 | 23 | all:test 24 | 25 | test:$(OBJS) 26 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 27 | 28 | cleanlocal: 29 | rm -f *.o a.out *~ test rdestl/*.o rdestl/*~ 30 | 31 | clean:cleanlocal 32 | 33 | -------------------------------------------------------------------------------- /src/runit/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 | typedef struct /* static system information */ 11 | { 12 | size_t mem_total, page_size, swap_total; 13 | } RunSysStatic; 14 | 15 | typedef struct /* dynamic system information */ 16 | { 17 | double wall_clock; 18 | size_t mem_free, mem_available; 19 | } RunSysDyn; 20 | 21 | typedef struct /* dynamic process information */ 22 | { 23 | size_t rss, vsize; 24 | double utime, stime; 25 | } RunProcDyn; 26 | 27 | int run_get_static_sys_info(RunSysStatic *rss); 28 | int run_get_dynamic_sys_info(RunSysDyn *rsd); 29 | int run_get_dynamic_proc_info(pid_t pid, RunProcDyn *rpd); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/rdestl/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer -Wno-deprecated -Wno-unused-value -Wno-uninitialized 4 | CXXFLAGS= $(CFLAGS) 5 | OBJS= ../benchmark/benchmark.o ../runit/runlib.o test.o \ 6 | rdestl/allocator.o rdestl/intrusive_list.o \ 7 | rdestl/list.o rdestl/slist.o 8 | DFLAGS= 9 | INCLUDES= -I../benchmark -I../runit -I. 10 | LIBS= 11 | 12 | .SUFFIXES:.c .o .cc .cpp 13 | 14 | .c.o: 15 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DFLAGS) $< -o $@ 16 | 17 | .cc.o: 18 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 19 | 20 | .cpp.o: 21 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DFLAGS) $< -o $@ 22 | 23 | all:test 24 | 25 | test:$(OBJS) 26 | $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS) 27 | 28 | cleanlocal: 29 | rm -f *.o a.out *~ test rdestl/*.o rdestl/*~ 30 | 31 | clean:cleanlocal 32 | 33 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/fixed_sorted_vector.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FIXED_SORTED_VECTOR_H 2 | #define RDESTL_FIXED_SORTED_VECTOR_H 3 | 4 | #include "rdestl/fixed_vector.h" 5 | #include "rdestl/sorted_vector.h" 6 | 7 | namespace rde 8 | { 9 | template, 11 | class TAllocator = rde::allocator> 12 | class fixed_sorted_vector : public sorted_vector, TAllocator, TCapacity, 15 | TGrowOnOverflow> > 16 | { 17 | public: 18 | explicit fixed_sorted_vector(const allocator_type& allocator = allocator_type()) 19 | : sorted_vector(allocator) 20 | { 21 | /**/ 22 | } 23 | }; 24 | 25 | } // rde 26 | 27 | #endif // #ifndef RDESTL_FIXED_SORTED_VECTOR_H 28 | 29 | -------------------------------------------------------------------------------- /src/khash/test.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | #include "khash.h" 4 | KHASH_MAP_INIT_INT(int, int) 5 | KHASH_MAP_INIT_STR(str, int) 6 | 7 | int test_int(int N, const unsigned *data) 8 | { 9 | int i, ret; 10 | khash_t(int) *h; 11 | unsigned k; 12 | h = kh_init(int); 13 | for (i = 0; i < N; ++i) { 14 | k = kh_put(int, h, data[i], &ret); 15 | if (!ret) kh_del(int, h, k); 16 | else kh_value(h, k) = i; 17 | } 18 | ret = (int)kh_size(h); 19 | kh_destroy(int, h); 20 | return ret; 21 | } 22 | int test_str(int N, char * const *data) 23 | { 24 | int i, ret; 25 | khash_t(str) *h; 26 | unsigned k; 27 | h = kh_init(str); 28 | for (i = 0; i < N; ++i) { 29 | k = kh_put(str, h, data[i], &ret); 30 | if (!ret) kh_del(str, h, k); 31 | else kh_value(h, k) = i; 32 | } 33 | ret = (int)kh_size(h); 34 | kh_destroy(str, h); 35 | return ret; 36 | } 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | return udb_benchmark(argc, argv, test_int, test_str); 41 | } 42 | -------------------------------------------------------------------------------- /src/stb_hash/test.c.ORG: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | #define STB_DEFINE 4 | #define AC_REVISION 5 | #include "stb.h" 6 | 7 | int test_int(int N, const unsigned *data) 8 | { 9 | int i, ret, *x, n = 0; 10 | stb_idict *h; 11 | h = stb_idict_create(); 12 | for (i = 0; i < N; ++i) { 13 | ret = stb_idict_set(h, data[i], i); 14 | if (!ret) { 15 | --n; 16 | stb_idict_remove(h, data[i], x); 17 | } else ++n; 18 | } 19 | ret = n; 20 | stb_idict_destroy(h); 21 | return ret; 22 | } 23 | int test_str(int N, char * const *data) 24 | { 25 | int i, ret, *x, n = 0; 26 | stb_sdict *h; 27 | h = stb_sdict_create(); 28 | for (i = 0; i < N; ++i) { 29 | ret = stb_sdict_set(h, data[i], 0); 30 | if (!ret) { 31 | --n; 32 | stb_sdict_remove(h, data[i], x); 33 | } else ++n; 34 | } 35 | ret = n; 36 | stb_sdict_destroy(h); 37 | return ret; 38 | } 39 | 40 | int main(int argc, char *argv[]) 41 | { 42 | return udb_benchmark(argc, argv, test_int, test_str); 43 | } 44 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/allocator.cpp: -------------------------------------------------------------------------------- 1 | #include "rdestl/allocator.h" 2 | #include 3 | 4 | namespace rde 5 | { 6 | //----------------------------------------------------------------------------- 7 | void* allocator::allocate(size_t bytes, int /*flags*/) 8 | { 9 | return operator new(bytes); 10 | } 11 | 12 | //----------------------------------------------------------------------------- 13 | #if 0 14 | void* allocator::allocate_aligned(size_t bytes, size_t alignment, int /*flags*/) 15 | { 16 | // TODO: IMPLEMENT 17 | return 0; 18 | } 19 | #endif 20 | 21 | //----------------------------------------------------------------------------- 22 | void allocator::deallocate(void* ptr, size_t /*bytes*/) 23 | { 24 | if (ptr) 25 | operator delete(ptr); 26 | } 27 | 28 | //----------------------------------------------------------------------------- 29 | const char* allocator::get_name() const 30 | { 31 | return m_name; 32 | } 33 | 34 | } // rde 35 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/intrusive_slist.cpp: -------------------------------------------------------------------------------- 1 | #include "rdestl/intrusive_slist.h" 2 | 3 | namespace rde 4 | { 5 | intrusive_slist_base::intrusive_slist_base() 6 | { 7 | /**/ 8 | } 9 | 10 | intrusive_slist_base::size_type intrusive_slist_base::size() const 11 | { 12 | size_type numNodes(0); 13 | const intrusive_slist_node* iter = &m_root; 14 | do 15 | { 16 | iter = iter->next; 17 | ++numNodes; 18 | } while (iter != &m_root); 19 | return numNodes - 1; 20 | } 21 | 22 | void intrusive_slist_base::link_after(intrusive_slist_node* node, intrusive_slist_node* prevNode) 23 | { 24 | RDE_ASSERT(!node->in_list()); 25 | node->next = prevNode->next; 26 | prevNode->next = node; 27 | } 28 | void intrusive_slist_base::unlink_after(intrusive_slist_node* node) 29 | { 30 | RDE_ASSERT(node->in_list()); 31 | intrusive_slist_node* thisNode = node->next; 32 | node->next = thisNode->next; 33 | thisNode->next = thisNode; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/stb_hash/test.c: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | 3 | #define STB_DEFINE 4 | #define AC_REVISION 5 | #include "stb.h" 6 | 7 | int test_int(int N, const unsigned *data) 8 | { 9 | int i, ret, *x, n = 0; 10 | stb_idict *h; 11 | h = stb_idict_create(); 12 | for (i = 0; i < N; ++i) { 13 | ret = stb_idict_set(h, data[i], i); 14 | if (!ret) { 15 | --n; 16 | stb_idict_remove(h, data[i], x); 17 | } else ++n; 18 | } 19 | ret = n; 20 | stb_idict_destroy(h); 21 | return ret; 22 | } 23 | int test_str(int N, char * const *data) 24 | { 25 | int i, ret, n = 0; 26 | void *x; 27 | stb_sdict *h; 28 | h = stb_sdict_create(); 29 | for (i = 0; i < N; ++i) { 30 | ret = stb_sdict_set(h, data[i], 0); 31 | if (!ret) { 32 | --n; 33 | stb_sdict_remove(h, data[i], & x); 34 | } else ++n; 35 | } 36 | ret = n; 37 | stb_sdict_destroy(h); 38 | return ret; 39 | } 40 | 41 | int main(int argc, char *argv[]) 42 | { 43 | return udb_benchmark(argc, argv, test_int, test_str); 44 | } 45 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # The list of directories to compile 2 | SUBDIRS = src 3 | 4 | # The main target is responsible to compile all 5 | all: 6 | @for dir in ${SUBDIRS} ; do \ 7 | if [ -d $$dir ] ; then \ 8 | echo "Making sub-directory $$dir ..." ; \ 9 | (cd $$dir && make -s) ; \ 10 | fi \ 11 | done 12 | 13 | # Cleanup rules 14 | clean distclean: 15 | @rm -f *~ 16 | @for dir in ${SUBDIRS} ; do \ 17 | if [ -d $$dir ] ; then \ 18 | (cd $$dir && make -s clean) ; \ 19 | fi \ 20 | done 21 | 22 | # Run tests 23 | DRIVER = src/runit/runit 24 | PROGRAMS = $(shell ls -1 src/*/test) 25 | TYPES = i s 26 | run: 27 | @for t in ${TYPES}; do \ 28 | for p in ${PROGRAMS} ; do \ 29 | if [ -x $$p ] ; then \ 30 | echo "Running test $$p (-$$t). Please wait ..." ; \ 31 | ${DRIVER} $$p -$$t ; \ 32 | fi \ 33 | done \ 34 | done 35 | -------------------------------------------------------------------------------- /src/rdestl/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/rdestl/intrusive_list.cpp: -------------------------------------------------------------------------------- 1 | #include "rdestl/intrusive_list.h" 2 | 3 | namespace rde 4 | { 5 | intrusive_list_base::intrusive_list_base() 6 | : m_root() 7 | { 8 | /**/ 9 | } 10 | 11 | intrusive_list_base::size_type intrusive_list_base::size() const 12 | { 13 | size_type numNodes(0); 14 | const intrusive_list_node* iter = &m_root; 15 | do 16 | { 17 | iter = iter->next; 18 | ++numNodes; 19 | } while (iter != &m_root); 20 | return numNodes - 1; 21 | } 22 | 23 | void intrusive_list_base::link(intrusive_list_node* node, intrusive_list_node* nextNode) 24 | { 25 | RDE_ASSERT(!node->in_list()); 26 | node->prev = nextNode->prev; 27 | node->prev->next = node; 28 | nextNode->prev = node; 29 | node->next = nextNode; 30 | } 31 | void intrusive_list_base::unlink(intrusive_list_node* node) 32 | { 33 | RDE_ASSERT(node->in_list()); 34 | node->prev->next = node->next; 35 | node->next->prev = node->prev; 36 | node->next = node->prev = node; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/_qt_qmap/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | #include 5 | 6 | //#define SIMPLE_STR 7 | 8 | struct mystr_t { 9 | const char *s; 10 | }; 11 | inline bool operator < (const mystr_t &a, const mystr_t &b) { return strcmp(a.s, b.s) < 0; } 12 | 13 | typedef QMap inthash; 14 | typedef QMap strhash; 15 | 16 | int test_int(int N, const unsigned *data) 17 | { 18 | int i, ret; 19 | inthash *h = new inthash; 20 | for (i = 0; i < N; ++i) { 21 | if (h->remove(data[i]) == 0) h->insert(data[i], i); 22 | } 23 | ret = h->count(); 24 | delete h; 25 | return ret; 26 | } 27 | 28 | int test_str(int N, char *const *data) 29 | { 30 | int i, ret; 31 | strhash *h = new strhash; 32 | mystr_t p; 33 | for (i = 0; i < N; ++i) { 34 | p.s = data[i]; 35 | if (h->remove(p) == 0) h->insert(p, i); 36 | } 37 | ret = h->count(); 38 | delete h; 39 | return ret; 40 | } 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | return udb_benchmark(argc, argv, test_int, test_str); 45 | } 46 | -------------------------------------------------------------------------------- /src/stx_btree/stx/btree: -------------------------------------------------------------------------------- 1 | // $Id: btree.h 13 2007-03-04 22:58:47Z tb $ 2 | /** \file btree 3 | * Forwarder header to btree.h 4 | */ 5 | 6 | /* 7 | * STX B+ Tree Template Classes v0.8.3 8 | * Copyright (C) 2008 Timo Bingmann 9 | * 10 | * This library is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU Lesser General Public License as published by the 12 | * Free Software Foundation; either version 2.1 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this library; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _STX_BTREE_ 26 | #define _STX_BTREE_ 27 | 28 | #include 29 | 30 | #endif // _STX_BTREE_ 31 | -------------------------------------------------------------------------------- /src/sgi_map/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct ltstr { 8 | inline bool operator()(const char *s1, const char *s2) const { 9 | return strcmp(s1, s2) < 0; 10 | } 11 | }; 12 | 13 | typedef map inthash; 14 | typedef map strhash; 15 | 16 | int test_int(int N, const unsigned *data) 17 | { 18 | int i, ret; 19 | inthash *h = new inthash; 20 | for (i = 0; i < N; ++i) { 21 | pair p = h->insert(pair(data[i], i)); 22 | if (p.second == false) h->erase(p.first); 23 | } 24 | ret = h->size(); 25 | delete h; 26 | return ret; 27 | } 28 | 29 | int test_str(int N, char * const *data) 30 | { 31 | int i, ret; 32 | strhash *h = new strhash; 33 | for (i = 0; i < N; ++i) { 34 | pair p = h->insert(pair(data[i], i)); 35 | if (p.second == false) h->erase(p.first); 36 | } 37 | ret = h->size(); 38 | delete h; 39 | return ret; 40 | } 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | return udb_benchmark(argc, argv, test_int, test_str); 45 | } 46 | -------------------------------------------------------------------------------- /src/sgi_map/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct ltstr { 9 | inline bool operator()(const char *s1, const char *s2) const { 10 | return strcmp(s1, s2) < 0; 11 | } 12 | }; 13 | 14 | typedef map inthash; 15 | typedef map strhash; 16 | 17 | int test_int(int N, const unsigned *data) 18 | { 19 | int i, ret; 20 | inthash *h = new inthash; 21 | for (i = 0; i < N; ++i) { 22 | pair p = h->insert(pair(data[i], i)); 23 | if (p.second == false) h->erase(p.first); 24 | } 25 | ret = h->size(); 26 | delete h; 27 | return ret; 28 | } 29 | 30 | int test_str(int N, char * const *data) 31 | { 32 | int i, ret; 33 | strhash *h = new strhash; 34 | for (i = 0; i < N; ++i) { 35 | pair p = h->insert(pair(data[i], i)); 36 | if (p.second == false) h->erase(p.first); 37 | } 38 | ret = h->size(); 39 | delete h; 40 | return ret; 41 | } 42 | 43 | int main(int argc, char *argv[]) 44 | { 45 | return udb_benchmark(argc, argv, test_int, test_str); 46 | } 47 | -------------------------------------------------------------------------------- /src/stx_btree/stx/btree_map: -------------------------------------------------------------------------------- 1 | // $Id: btree.h 13 2007-03-04 22:58:47Z tb $ 2 | /** \file btree_map 3 | * Forwarder header to btree_map.h 4 | */ 5 | 6 | /* 7 | * STX B+ Tree Template Classes v0.8.3 8 | * Copyright (C) 2008 Timo Bingmann 9 | * 10 | * This library is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU Lesser General Public License as published by the 12 | * Free Software Foundation; either version 2.1 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this library; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _STX_BTREE_MAP_ 26 | #define _STX_BTREE_MAP_ 27 | 28 | #include 29 | 30 | #endif // _STX_BTREE_MAP_ 31 | -------------------------------------------------------------------------------- /src/stx_btree/stx/btree_set: -------------------------------------------------------------------------------- 1 | // $Id: btree.h 13 2007-03-04 22:58:47Z tb $ 2 | /** \file btree_set 3 | * Forwarder header to btree_set.h 4 | */ 5 | 6 | /* 7 | * STX B+ Tree Template Classes v0.8.3 8 | * Copyright (C) 2008 Timo Bingmann 9 | * 10 | * This library is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU Lesser General Public License as published by the 12 | * Free Software Foundation; either version 2.1 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this library; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _STX_BTREE_SET_ 26 | #define _STX_BTREE_SET_ 27 | 28 | #include 29 | 30 | #endif // _STX_BTREE_SET_ 31 | -------------------------------------------------------------------------------- /src/stx_btree/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct ltstr { 8 | inline bool operator()(const char *s1, const char *s2) const { 9 | return strcmp(s1, s2) < 0; 10 | } 11 | }; 12 | 13 | typedef stx::btree_map inthash; 14 | typedef stx::btree_map strhash; 15 | 16 | int test_int(int N, const unsigned *data) 17 | { 18 | int i, ret; 19 | inthash *h = new inthash; 20 | for (i = 0; i < N; ++i) { 21 | pair p = h->insert(pair(data[i], i)); 22 | if (p.second == false) h->erase_one(data[i]); 23 | } 24 | ret = h->size(); 25 | delete h; 26 | return ret; 27 | } 28 | 29 | int test_str(int N, char * const *data) 30 | { 31 | int i, ret; 32 | strhash *h = new strhash; 33 | for (i = 0; i < N; ++i) { 34 | pair p = h->insert(pair(data[i], i)); 35 | if (p.second == false) h->erase(data[i]); 36 | } 37 | ret = h->size(); 38 | delete h; 39 | return ret; 40 | } 41 | 42 | int main(int argc, char *argv[]) 43 | { 44 | return udb_benchmark(argc, argv, test_int, test_str); 45 | } 46 | -------------------------------------------------------------------------------- /src/_glib_tree/test.c.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include 7 | 8 | static inline int intcmp(const void *a, const void *b) 9 | { 10 | return (*(unsigned*)a > *(unsigned*)b) - (*(unsigned*)a < *(unsigned*)b); 11 | } 12 | 13 | int test_int(int N, const unsigned *data) 14 | { 15 | int i, *p, n = 0; 16 | GTree *h; 17 | h = g_tree_new_full(intcmp, 0, 0, free); 18 | for (i = 0; i < N; ++i) { 19 | if (!g_tree_remove(h, &data[i])) { 20 | p = (int*)malloc(sizeof(int)); 21 | *p = i; 22 | g_tree_insert(h, &data[i], p); 23 | ++n; 24 | } else --n; 25 | } 26 | g_tree_destroy(h); 27 | return n; 28 | } 29 | int test_str(int N, char * const *data) 30 | { 31 | int i, *p, n = 0; 32 | GTree *h; 33 | h = g_tree_new_full(strcmp, 0, 0, free); 34 | for (i = 0; i < N; ++i) { 35 | if (!g_tree_remove(h, data[i])) { 36 | p = (int*)malloc(sizeof(int)); 37 | *p = i; 38 | g_tree_insert(h, data[i], p); 39 | ++n; 40 | } else --n; 41 | } 42 | g_tree_destroy(h); 43 | return n; 44 | } 45 | 46 | int main(int argc, char *argv[]) 47 | { 48 | return udb_benchmark(argc, argv, test_int, test_str); 49 | } 50 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | 3 | The MIT License 4 | 5 | Copyright (c) 2007 Maciej Sinilo 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /src/stx_btree/stx/btree_multimap: -------------------------------------------------------------------------------- 1 | // $Id: btree.h 13 2007-03-04 22:58:47Z tb $ 2 | /** \file btree_multimap 3 | * Forwarder header to btree_multimap.h 4 | */ 5 | 6 | /* 7 | * STX B+ Tree Template Classes v0.8.3 8 | * Copyright (C) 2008 Timo Bingmann 9 | * 10 | * This library is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU Lesser General Public License as published by the 12 | * Free Software Foundation; either version 2.1 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this library; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _STX_BTREE_MULTIMAP_ 26 | #define _STX_BTREE_MULTIMAP_ 27 | 28 | #include 29 | 30 | #endif // _STX_BTREE_MULTIMAP_ 31 | -------------------------------------------------------------------------------- /src/stx_btree/stx/btree_multiset: -------------------------------------------------------------------------------- 1 | // $Id: btree.h 13 2007-03-04 22:58:47Z tb $ 2 | /** \file btree_multiset 3 | * Forwarder header to btree_multiset.h 4 | */ 5 | 6 | /* 7 | * STX B+ Tree Template Classes v0.8.3 8 | * Copyright (C) 2008 Timo Bingmann 9 | * 10 | * This library is free software; you can redistribute it and/or modify it 11 | * under the terms of the GNU Lesser General Public License as published by the 12 | * Free Software Foundation; either version 2.1 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * This library is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this library; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _STX_BTREE_MULTISET_ 26 | #define _STX_BTREE_MULTISET_ 27 | 28 | #include 29 | 30 | #endif // _STX_BTREE_MULTISET_ 31 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/buffer_allocator.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_BUFFER_ALLOCATOR_H 2 | #define RDESTL_BUFFER_ALLOCATOR_H 3 | 4 | #include "rdestl/rdestl.h" 5 | 6 | namespace rde 7 | { 8 | 9 | // CONCEPT! 10 | class buffer_allocator 11 | { 12 | public: 13 | explicit buffer_allocator(const char* name, char* mem, 14 | size_t bufferSize) 15 | : m_name(name), 16 | m_buffer(mem), 17 | m_bufferTop(0), 18 | m_bufferSize(bufferSize) 19 | { 20 | /**/ 21 | } 22 | 23 | void* allocate(size_t bytes, int /*flags*/ = 0) 24 | { 25 | RDE_ASSERT(m_bufferTop + bytes <= m_bufferSize); 26 | char* ret = m_buffer + m_bufferTop; 27 | m_bufferTop += bytes; 28 | return ret; 29 | } 30 | void deallocate(void* ptr, size_t /*bytes*/) 31 | { 32 | RDE_ASSERT(ptr == 0 || (ptr >= m_buffer && ptr < m_buffer + m_bufferSize)); 33 | sizeof(ptr); 34 | } 35 | 36 | const char* get_name() const { return m_name; } 37 | 38 | private: 39 | const char* m_name; 40 | char* m_buffer; 41 | size_t m_bufferTop; 42 | size_t m_bufferSize; 43 | }; 44 | 45 | } // namespace rde 46 | //----------------------------------------------------------------------------- 47 | #endif // #ifndef RDESTL_BUFFER_ALLOCATOR_H 48 | -------------------------------------------------------------------------------- /src/_glib_tree/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include 7 | 8 | static inline int intcmp(const void *a, const void *b) 9 | { 10 | return (*(unsigned*)a > *(unsigned*)b) - (*(unsigned*)a < *(unsigned*)b); 11 | } 12 | 13 | int test_int(int N, const unsigned *data) 14 | { 15 | int i, *p, n = 0; 16 | GTree *h; 17 | h = g_tree_new_full((GCompareDataFunc) intcmp, 0, 0, free); 18 | for (i = 0; i < N; ++i) { 19 | if (!g_tree_remove(h, &data[i])) { 20 | p = (int*)malloc(sizeof(int)); 21 | *p = i; 22 | g_tree_insert(h, (unsigned *) &data[i], p); 23 | ++n; 24 | } else --n; 25 | } 26 | g_tree_destroy(h); 27 | return n; 28 | } 29 | int test_str(int N, char * const *data) 30 | { 31 | int i, *p, n = 0; 32 | GTree *h; 33 | h = g_tree_new_full((GCompareDataFunc) strcmp, 0, 0, free); 34 | for (i = 0; i < N; ++i) { 35 | if (!g_tree_remove(h, data[i])) { 36 | p = (int*)malloc(sizeof(int)); 37 | *p = i; 38 | g_tree_insert(h, data[i], p); 39 | ++n; 40 | } else --n; 41 | } 42 | g_tree_destroy(h); 43 | return n; 44 | } 45 | 46 | int main(int argc, char *argv[]) 47 | { 48 | return udb_benchmark(argc, argv, test_int, test_str); 49 | } 50 | -------------------------------------------------------------------------------- /src/sgi_hash_map/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | using namespace __gnu_cxx; 7 | 8 | struct eqstr { 9 | inline bool operator()(const char *s1, const char *s2) const { 10 | return strcmp(s1, s2) == 0; 11 | } 12 | }; 13 | 14 | typedef hash_map > inthash; 15 | typedef hash_map, eqstr> strhash; 16 | 17 | int test_int(int N, const unsigned *data) 18 | { 19 | int i, ret; 20 | inthash *h = new inthash; 21 | for (i = 0; i < N; ++i) { 22 | pair p = h->insert(pair(data[i], i)); 23 | if (p.second == false) h->erase(p.first); 24 | } 25 | ret = h->size(); 26 | delete h; 27 | return ret; 28 | } 29 | 30 | int test_str(int N, char * const *data) 31 | { 32 | int i, ret; 33 | strhash *h = new strhash; 34 | for (i = 0; i < N; ++i) { 35 | pair p = h->insert(pair(data[i], i)); 36 | if (p.second == false) h->erase(p.first); 37 | } 38 | ret = h->size(); 39 | delete h; 40 | return ret; 41 | } 42 | 43 | int main(int argc, char *argv[]) 44 | { 45 | return udb_benchmark(argc, argv, test_int, test_str); 46 | } 47 | -------------------------------------------------------------------------------- /src/stx_btree/test.cc: -------------------------------------------------------------------------------- 1 | typedef long ptrdiff_t; 2 | 3 | #include "benchmark.h" 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | struct ltstr { 11 | inline bool operator()(const char *s1, const char *s2) const { 12 | return strcmp(s1, s2) < 0; 13 | } 14 | }; 15 | 16 | typedef stx::btree_map inthash; 17 | typedef stx::btree_map strhash; 18 | 19 | int test_int(int N, const unsigned *data) 20 | { 21 | int i, ret; 22 | inthash *h = new inthash; 23 | for (i = 0; i < N; ++i) { 24 | pair p = h->insert(pair(data[i], i)); 25 | if (p.second == false) h->erase_one(data[i]); 26 | } 27 | ret = h->size(); 28 | delete h; 29 | return ret; 30 | } 31 | 32 | int test_str(int N, char * const *data) 33 | { 34 | int i, ret; 35 | strhash *h = new strhash; 36 | for (i = 0; i < N; ++i) { 37 | pair p = h->insert(pair(data[i], i)); 38 | if (p.second == false) h->erase(data[i]); 39 | } 40 | ret = h->size(); 41 | delete h; 42 | return ret; 43 | } 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | return udb_benchmark(argc, argv, test_int, test_str); 48 | } 49 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/string_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_STRING_UTILS_H 2 | #define RDESTL_STRING_UTILS_H 3 | 4 | namespace rde 5 | { 6 | //----------------------------------------------------------------------------- 7 | template int strlen(const T* str) 8 | { 9 | int len(0); 10 | while (*str++) 11 | ++len; 12 | return len; 13 | } 14 | 15 | //----------------------------------------------------------------------------- 16 | template int strcompare(const T* s1, const T* s2, size_t len) 17 | { 18 | for (/**/; len != 0; --len) 19 | { 20 | const T c1 = *s1; 21 | const T c2 = *s2; 22 | if (c1 != c2) 23 | return (c1 < c2 ? -1 : 1); 24 | 25 | ++s1; 26 | ++s2; 27 | } 28 | return 0; 29 | } 30 | 31 | //----------------------------------------------------------------------------- 32 | template int strcompare(const T* s1, const T* s2) 33 | { 34 | while (*s1 && *s2) 35 | { 36 | const T c1 = *s1; 37 | const T c2 = *s2; 38 | if (c1 != c2) 39 | return (c1 < c2 ? -1 : 1); 40 | 41 | ++s1; 42 | ++s2; 43 | } 44 | if (*s1) 45 | return 1; 46 | if (*s2) 47 | return -1; 48 | return 0; 49 | } 50 | 51 | } // rde 52 | 53 | #endif // RDESTL_STRING_UTILS_H 54 | -------------------------------------------------------------------------------- /src/tr1_unordered_map/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std::tr1; 6 | using namespace std; 7 | 8 | struct eqstr { 9 | inline bool operator()(const char *s1, const char *s2) const { 10 | return strcmp(s1, s2) == 0; 11 | } 12 | }; 13 | 14 | typedef unordered_map > inthash; 15 | typedef unordered_map, eqstr> strhash; 16 | 17 | int test_int(int N, const unsigned *data) 18 | { 19 | int i, ret; 20 | inthash *h = new inthash; 21 | for (i = 0; i < N; ++i) { 22 | pair p = h->insert(pair(data[i], i)); 23 | if (p.second == false) h->erase(p.first); 24 | } 25 | ret = h->size(); 26 | delete h; 27 | return ret; 28 | } 29 | 30 | int test_str(int N, char * const *data) 31 | { 32 | int i, ret; 33 | strhash *h = new strhash; 34 | for (i = 0; i < N; ++i) { 35 | pair p = h->insert(pair(data[i], i)); 36 | if (p.second == false) h->erase(p.first); 37 | } 38 | ret = h->size(); 39 | delete h; 40 | return ret; 41 | } 42 | 43 | int main(int argc, char *argv[]) 44 | { 45 | return udb_benchmark(argc, argv, test_int, test_str); 46 | } 47 | -------------------------------------------------------------------------------- /src/_qt_qhash/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | struct mystr_t { 6 | const char *s; 7 | }; 8 | inline bool operator == (const mystr_t &a, const mystr_t &b) { return strcmp(a.s, b.s) == 0; } 9 | static inline unsigned __ac_X31_hash_string(const char *s) 10 | { 11 | unsigned h = *s; 12 | if (h) for (++s ; *s; ++s) h = (h << 5) - h + *s; 13 | return h; 14 | } 15 | inline uint qHash(const mystr_t &a) 16 | { 17 | return __ac_X31_hash_string(a.s); 18 | } 19 | 20 | typedef QHash inthash; 21 | typedef QHash strhash; 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | int i, ret; 26 | inthash *h = new inthash; 27 | for (i = 0; i < N; ++i) { 28 | if (h->remove(data[i]) == 0) h->insert(data[i], i); 29 | } 30 | ret = h->count(); 31 | delete h; 32 | return ret; 33 | } 34 | 35 | int test_str(int N, char *const *data) 36 | { 37 | int i, ret; 38 | strhash *h = new strhash; 39 | mystr_t p; 40 | for (i = 0; i < N; ++i) { 41 | p.s = data[i]; 42 | if (h->remove(p) == 0) h->insert(p, i); 43 | } 44 | ret = h->count(); 45 | delete h; 46 | return ret; 47 | } 48 | 49 | int main(int argc, char *argv[]) 50 | { 51 | return udb_benchmark(argc, argv, test_int, test_str); 52 | } 53 | -------------------------------------------------------------------------------- /src/tr1_unordered_map/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std::tr1; 7 | using namespace std; 8 | 9 | struct eqstr { 10 | inline bool operator()(const char *s1, const char *s2) const { 11 | return strcmp(s1, s2) == 0; 12 | } 13 | }; 14 | 15 | typedef unordered_map > inthash; 16 | typedef unordered_map, eqstr> strhash; 17 | 18 | int test_int(int N, const unsigned *data) 19 | { 20 | int i, ret; 21 | inthash *h = new inthash; 22 | for (i = 0; i < N; ++i) { 23 | pair p = h->insert(pair(data[i], i)); 24 | if (p.second == false) h->erase(p.first); 25 | } 26 | ret = h->size(); 27 | delete h; 28 | return ret; 29 | } 30 | 31 | int test_str(int N, char * const *data) 32 | { 33 | int i, ret; 34 | strhash *h = new strhash; 35 | for (i = 0; i < N; ++i) { 36 | pair p = h->insert(pair(data[i], i)); 37 | if (p.second == false) h->erase(p.first); 38 | } 39 | ret = h->size(); 40 | delete h; 41 | return ret; 42 | } 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | return udb_benchmark(argc, argv, test_int, test_str); 47 | } 48 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/pair.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_PAIR_H 2 | #define RDESTL_PAIR_H 3 | 4 | #include "rdestl/type_traits.h" 5 | 6 | namespace rde 7 | { 8 | //============================================================================= 9 | template 10 | struct pair 11 | { 12 | typedef T1 first_type; 13 | typedef T2 second_type; 14 | 15 | pair() {/**/} 16 | pair(const T1& a, const T2& b): first(a), second(b) {/**/} 17 | explicit pair(const T1& a): first(a) {/**/} 18 | 19 | T1 first; 20 | T2 second; 21 | }; 22 | 23 | //============================================================================= 24 | // Pair is POD if every element is POD/fundamental 25 | template struct is_pod > 26 | { 27 | enum { value = (is_pod::value || is_fundamental::value) && 28 | (is_pod::value || is_fundamental::value) }; 29 | }; 30 | 31 | //----------------------------------------------------------------------------- 32 | template 33 | pair make_pair(const T1& a, const T2& b) 34 | { 35 | return pair(a, b); 36 | } 37 | 38 | } 39 | 40 | //----------------------------------------------------------------------------- 41 | #endif // #ifndef RDESTL_PAIR_H 42 | -------------------------------------------------------------------------------- /src/uthash/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "benchmark.h" 3 | #include "uthash.h" 4 | 5 | typedef struct { 6 | unsigned key; 7 | int val; 8 | UT_hash_handle hh; 9 | } intcell_t; 10 | 11 | typedef struct { 12 | char *key; 13 | int val; 14 | UT_hash_handle hh; 15 | } strcell_t; 16 | 17 | int test_int(int N, const unsigned *data) 18 | { 19 | int i, n = 0; 20 | intcell_t *h = 0, *r; 21 | for (i = 0; i < N; ++i) { 22 | HASH_FIND_INT(h, &data[i], r); 23 | if (r == 0) { 24 | r = (intcell_t*)malloc(sizeof(intcell_t)); 25 | r->key = data[i]; r->val = i; 26 | HASH_ADD_INT(h, key, r); 27 | ++n; 28 | } else { 29 | HASH_DEL(h, r); 30 | free(r); 31 | --n; 32 | } 33 | } 34 | return n; 35 | } 36 | int test_str(int N, char * const *data) 37 | { 38 | int i, n = 0; 39 | strcell_t *h = 0, *r; 40 | for (i = 0; i < N; ++i) { 41 | HASH_FIND_STR(h, data[i], r); 42 | if (r == 0) { 43 | r = (strcell_t*)malloc(sizeof(strcell_t)); 44 | r->key = data[i]; r->val = i; 45 | HASH_ADD_KEYPTR(hh, h, r->key, strlen(r->key), r); 46 | ++n; 47 | } else { 48 | HASH_DEL(h, r); 49 | free(r); 50 | --n; 51 | } 52 | } 53 | return n; 54 | } 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | return udb_benchmark(argc, argv, test_int, test_str); 59 | } 60 | -------------------------------------------------------------------------------- /src/sgi_hash_map/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | using namespace __gnu_cxx; 8 | 9 | struct eqstr { 10 | inline bool operator()(const char *s1, const char *s2) const { 11 | return strcmp(s1, s2) == 0; 12 | } 13 | }; 14 | 15 | typedef hash_map > inthash; 16 | typedef hash_map, eqstr> strhash; 17 | 18 | 19 | int test_int(int N, const unsigned *data) 20 | { 21 | int i, ret; 22 | inthash *h = new inthash; 23 | for (i = 0; i < N; ++i) { 24 | pair p = h->insert(pair(data[i], i)); 25 | if (p.second == false) h->erase(p.first); 26 | } 27 | ret = h->size(); 28 | delete h; 29 | return ret; 30 | } 31 | 32 | int test_str(int N, char * const *data) 33 | { 34 | int i, ret; 35 | strhash *h = new strhash; 36 | for (i = 0; i < N; ++i) { 37 | pair p = h->insert(pair(data[i], i)); 38 | if (p.second == false) h->erase(p.first); 39 | } 40 | ret = h->size(); 41 | delete h; 42 | return ret; 43 | } 44 | 45 | int main(int argc, char *argv[]) 46 | { 47 | return udb_benchmark(argc, argv, test_int, test_str); 48 | } 49 | -------------------------------------------------------------------------------- /src/Makefile.ORG: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | CXX= g++ 3 | CFLAGS= -g -Wall -O2 -fomit-frame-pointer #-m64 4 | CXXFLAGS= $(CFLAGS) 5 | DFLAGS= 6 | OBJS= 7 | LIBS= 8 | SUBDIRS= kbtree khash \ 9 | sgi_map sgi_hash_map tr1_unordered_map \ 10 | stx_btree \ 11 | htable \ 12 | NP_rbtree NP_splaytree \ 13 | JG_btree \ 14 | JE_rb_new JE_rb_old JE_trp_hash JE_trp_prng \ 15 | google_dense google_sparse \ 16 | libavl_avl libavl_rb libavl_prb libavl_bst \ 17 | uthash \ 18 | TN_rbtree libavl_avl_cpp libavl_rb_cpp libavl_rb_cpp2 \ 19 | sglib_rbtree \ 20 | rdestl \ 21 | stb_hash \ 22 | runit 23 | 24 | .SUFFIXES:.c .o .cc 25 | 26 | .c.o: 27 | $(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@ 28 | .cc.o: 29 | $(CXX) -c $(CXXFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@ 30 | 31 | all:all-recur 32 | 33 | lib-recur all-recur clean-recur cleanlocal-recur install-recur: 34 | @target=`echo $@ | sed s/-recur//`; \ 35 | wdir=`pwd`; \ 36 | list='$(SUBDIRS)'; for subdir in $$list; do \ 37 | cd $$subdir; \ 38 | $(MAKE) CC="$(CC)" CXX="$(CXX)" DFLAGS="$(DFLAGS)" CFLAGS="$(CFLAGS)" \ 39 | $$target || exit 1; \ 40 | cd $$wdir; \ 41 | done; 42 | 43 | lib: 44 | 45 | cleanlocal: 46 | rm -f gmon.out *.o stdhash/*.o a.out *~ *.a 47 | 48 | clean:cleanlocal-recur 49 | find . -name "*~"|xargs rm -------------------------------------------------------------------------------- /src/google_sparse/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct eqstr { 8 | inline bool operator()(const char *s1, const char *s2) const { 9 | return strcmp(s1, s2) == 0; 10 | } 11 | }; 12 | 13 | typedef google::sparse_hash_map > inthash; 14 | typedef google::sparse_hash_map, eqstr> strhash; 15 | 16 | int test_int(int N, const unsigned *data) 17 | { 18 | int i, ret; 19 | inthash *h = new inthash; 20 | h->set_deleted_key(0xfffffffeu); 21 | for (i = 0; i < N; ++i) { 22 | pair p = h->insert(pair(data[i], i)); 23 | if (p.second == false) h->erase(p.first); 24 | } 25 | ret = h->size(); 26 | delete h; 27 | return ret; 28 | } 29 | 30 | int test_str(int N, char * const *data) 31 | { 32 | int i, ret; 33 | strhash *h = new strhash; 34 | h->set_deleted_key(""); 35 | for (i = 0; i < N; ++i) { 36 | pair p = h->insert(pair(data[i], i)); 37 | if (p.second == false) h->erase(p.first); 38 | } 39 | ret = h->size(); 40 | delete h; 41 | return ret; 42 | } 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | return udb_benchmark(argc, argv, test_int, test_str); 47 | } 48 | -------------------------------------------------------------------------------- /src/google_sparse/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct eqstr { 8 | inline bool operator()(const char *s1, const char *s2) const { 9 | return strcmp(s1, s2) == 0; 10 | } 11 | }; 12 | 13 | typedef google::sparse_hash_map > inthash; 14 | typedef google::sparse_hash_map, eqstr> strhash; 15 | 16 | int test_int(int N, const unsigned *data) 17 | { 18 | int i, ret; 19 | inthash *h = new inthash; 20 | h->set_deleted_key(0xfffffffeu); 21 | for (i = 0; i < N; ++i) { 22 | pair p = h->insert(pair(data[i], i)); 23 | if (p.second == false) h->erase(p.first); 24 | } 25 | ret = h->size(); 26 | delete h; 27 | return ret; 28 | } 29 | 30 | int test_str(int N, char * const *data) 31 | { 32 | int i, ret; 33 | strhash *h = new strhash; 34 | h->set_deleted_key(""); 35 | for (i = 0; i < N; ++i) { 36 | pair p = h->insert(pair(data[i], i)); 37 | if (p.second == false) h->erase(p.first); 38 | } 39 | ret = h->size(); 40 | delete h; 41 | return ret; 42 | } 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | return udb_benchmark(argc, argv, test_int, test_str); 47 | } 48 | -------------------------------------------------------------------------------- /src/sgi_map/test2.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | struct ltint { 18 | inline bool operator()(void *_a, void *_b) const { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return a->key < b->key; 22 | } 23 | }; 24 | 25 | struct ltstr { 26 | inline bool operator()(void *a, void *b) { 27 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 28 | } 29 | }; 30 | 31 | typedef set inthash; 32 | typedef set strhash; 33 | 34 | int test_int(int N, const unsigned *data) 35 | { 36 | int i, ret; 37 | intmap_t *d; 38 | inthash::iterator iter; 39 | inthash *h = new inthash; 40 | for (i = 0; i < N; ++i) { 41 | d = (intmap_t*)malloc(sizeof(intmap_t)); 42 | d->key = data[i]; d->value = i; 43 | iter = h->find(d); 44 | if (iter == h->end()) h->insert(d); 45 | else { 46 | h->erase(d); 47 | free(*iter); free(d); 48 | } 49 | } 50 | ret = h->size(); 51 | delete h; 52 | return ret; 53 | } 54 | 55 | int test_str(int N, char * const *data) 56 | { 57 | return 0; 58 | } 59 | 60 | int main(int argc, char *argv[]) 61 | { 62 | return udb_benchmark(argc, argv, test_int, test_str); 63 | } 64 | -------------------------------------------------------------------------------- /src/google_dense/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct eqstr { 8 | inline bool operator()(const char *s1, const char *s2) const { 9 | return strcmp(s1, s2) == 0; 10 | } 11 | }; 12 | 13 | typedef google::dense_hash_map > inthash; 14 | typedef google::dense_hash_map, eqstr> strhash; 15 | 16 | int test_int(int N, const unsigned *data) 17 | { 18 | int i, ret; 19 | inthash *h = new inthash; 20 | h->set_empty_key(0xffffffffu); 21 | h->set_deleted_key(0xfffffffeu); 22 | for (i = 0; i < N; ++i) { 23 | pair p = h->insert(pair(data[i], i)); 24 | if (p.second == false) h->erase(p.first); 25 | } 26 | ret = h->size(); 27 | delete h; 28 | return ret; 29 | } 30 | 31 | int test_str(int N, char * const *data) 32 | { 33 | int i, ret; 34 | strhash *h = new strhash; 35 | h->set_empty_key("*"); 36 | h->set_deleted_key(""); 37 | for (i = 0; i < N; ++i) { 38 | pair p = h->insert(pair(data[i], i)); 39 | if (p.second == false) h->erase(p.first); 40 | } 41 | ret = h->size(); 42 | delete h; 43 | return ret; 44 | } 45 | 46 | int main(int argc, char *argv[]) 47 | { 48 | return udb_benchmark(argc, argv, test_int, test_str); 49 | } 50 | -------------------------------------------------------------------------------- /src/google_dense/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct eqstr { 9 | inline bool operator()(const char *s1, const char *s2) const { 10 | return strcmp(s1, s2) == 0; 11 | } 12 | }; 13 | 14 | typedef google::dense_hash_map > inthash; 15 | typedef google::dense_hash_map, eqstr> strhash; 16 | 17 | int test_int(int N, const unsigned *data) 18 | { 19 | int i, ret; 20 | inthash *h = new inthash; 21 | h->set_empty_key(0xffffffffu); 22 | h->set_deleted_key(0xfffffffeu); 23 | for (i = 0; i < N; ++i) { 24 | pair p = h->insert(pair(data[i], i)); 25 | if (p.second == false) h->erase(p.first); 26 | } 27 | ret = h->size(); 28 | delete h; 29 | return ret; 30 | } 31 | 32 | int test_str(int N, char * const *data) 33 | { 34 | int i, ret; 35 | strhash *h = new strhash; 36 | h->set_empty_key("*"); 37 | h->set_deleted_key(""); 38 | for (i = 0; i < N; ++i) { 39 | pair p = h->insert(pair(data[i], i)); 40 | if (p.second == false) h->erase(p.first); 41 | } 42 | ret = h->size(); 43 | delete h; 44 | return ret; 45 | } 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | return udb_benchmark(argc, argv, test_int, test_str); 50 | } 51 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/rdestl.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_H 2 | #define RDESTL_H 3 | 4 | #ifndef RDESTL_STANDALONE 5 | # define RDESTL_STANDALONE 1 6 | #endif 7 | 8 | #if RDESTL_STANDALONE 9 | # include 10 | # include 11 | # define RDE_ASSERT assert 12 | // @note; __forceinline for MSVC! 13 | # define RDE_FORCEINLINE inline 14 | # ifdef _DEBUG 15 | # undef RDE_DEBUG 16 | # define RDE_DEBUG 1 17 | # endif 18 | namespace rde 19 | { 20 | // # Meh. MSVC doesnt seem to have 21 | // @todo Fixes to make this portable. 22 | typedef unsigned long uint32_t; 23 | namespace Sys 24 | { 25 | RDE_FORCEINLINE void MemCpy(void* to, const void* from, size_t bytes) 26 | { 27 | memcpy(to, from, bytes); 28 | } 29 | RDE_FORCEINLINE void MemMove(void* to, const void* from, size_t bytes) 30 | { 31 | memmove(to, from, bytes); 32 | } 33 | RDE_FORCEINLINE void MemSet(void* buf, unsigned char value, size_t bytes) 34 | { 35 | memset(buf, value, bytes); 36 | } 37 | } // sys 38 | } 39 | #else 40 | # include "core/RdeDebug.h" 41 | # include "core/System.h" 42 | #endif 43 | 44 | // Cache hash value in the node structure. 45 | // Costs 4 bytes per node, but hash doesnt have to be calculated during 46 | // rehashing and removing nodes in clusters. 47 | #define RDE_HASHMAP_CACHE_HASH 1 48 | 49 | #endif // #ifndef RDESTL_H 50 | -------------------------------------------------------------------------------- /src/_boost_hash/test.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark.h" 2 | #include 3 | #include 4 | 5 | using namespace boost; 6 | using namespace std; 7 | 8 | struct eqstr { 9 | inline bool operator()(const char *s1, const char *s2) const { 10 | return strcmp(s1, s2) == 0; 11 | } 12 | }; 13 | struct hashstr { 14 | inline std::size_t operator()(const char *s) const { 15 | size_t h = *s; 16 | if (h) for (++s ; *s; ++s) h = (h << 5) - h + *s; 17 | return h; 18 | } 19 | }; 20 | 21 | typedef unordered_map > inthash; 22 | typedef unordered_map strhash; 23 | 24 | int test_int(int N, const unsigned *data) 25 | { 26 | int i, ret; 27 | inthash *h = new inthash; 28 | for (i = 0; i < N; ++i) { 29 | pair p = h->insert(pair(data[i], i)); 30 | if (p.second == false) h->erase(p.first); 31 | } 32 | ret = h->size(); 33 | delete h; 34 | return ret; 35 | } 36 | 37 | int test_str(int N, char * const *data) 38 | { 39 | int i, ret; 40 | strhash *h = new strhash; 41 | for (i = 0; i < N; ++i) { 42 | pair p = h->insert(pair(data[i], i)); 43 | if (p.second == false) h->erase(p.first); 44 | } 45 | ret = h->size(); 46 | delete h; 47 | return ret; 48 | } 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | return udb_benchmark(argc, argv, test_int, test_str); 53 | } 54 | -------------------------------------------------------------------------------- /src/rdestl/test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "benchmark.h" 3 | #include "rdestl/hash_map.h" 4 | 5 | using namespace rde; 6 | 7 | struct eqstr { 8 | inline bool operator()(const char *s1, const char *s2) const { 9 | return strcmp(s1, s2) == 0; 10 | } 11 | }; 12 | struct hasher { 13 | inline rde::hash_value_t operator()(const char* s) const { 14 | rde::hash_value_t hash(0); 15 | char c; 16 | while ((c = *s++) != 0) 17 | hash = (hash << 5) + hash + c; 18 | return hash; 19 | } 20 | }; 21 | 22 | typedef rde::hash_map inthash; 23 | typedef rde::hash_map strhash; 24 | 25 | int test_int(int N, const unsigned *data) 26 | { 27 | int i, ret; 28 | inthash *h = new inthash; 29 | for (i = 0; i < N; ++i) { 30 | rde::pair p = h->insert(rde::pair(data[i], i)); 31 | if (p.second == false) h->erase(p.first); 32 | } 33 | ret = h->size(); 34 | delete h; 35 | return ret; 36 | } 37 | int test_str(int N, char * const *data) 38 | { 39 | int i, ret; 40 | strhash *h = new strhash; 41 | for (i = 0; i < N; ++i) { 42 | rde::pair p = h->insert(rde::pair(data[i], i)); 43 | if (p.second == false) h->erase(p.first); 44 | } 45 | ret = h->size(); 46 | delete h; 47 | return ret; 48 | } 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | return udb_benchmark(argc, argv, test_int, test_str); 53 | } 54 | -------------------------------------------------------------------------------- /src/TN_rbtree/test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "benchmark.h" 4 | #include "rb_tree.hh" 5 | 6 | typedef struct { 7 | unsigned key; 8 | int value; 9 | } intmap_t; 10 | 11 | typedef struct { 12 | char *key; 13 | int value; 14 | } strmap_t; 15 | 16 | struct int_cmp { 17 | inline int operator () (const intmap_t &a, const intmap_t &b) { 18 | return (a.key > b.key) - (a.key < b.key); 19 | } 20 | }; 21 | 22 | struct str_cmp { 23 | inline int operator () (const strmap_t &a, const strmap_t &b) { 24 | return strcmp(a.key, b.key); 25 | } 26 | }; 27 | 28 | typedef rb_tree inttree_t; 29 | typedef rb_tree strtree_t; 30 | 31 | int test_int(int N, const unsigned *data) 32 | { 33 | int i, n = 0; 34 | intmap_t d; 35 | inttree_t *h = new inttree_t; 36 | printf("[test_int] node size: %lu\n", sizeof(inttree_t::node_t)); 37 | for (i = 0; i < N; ++i) { 38 | d.key = data[i]; d.value = i; 39 | if (h->search(d) == 0) { h->insert(d); ++n; } 40 | else { h->erase(d); --n; } 41 | } 42 | delete h; 43 | return n; 44 | } 45 | int test_str(int N, char * const *data) 46 | { 47 | int i, n = 0; 48 | strmap_t d; 49 | strtree_t *h = new strtree_t; 50 | printf("[test_str] node size: %lu\n", sizeof(strtree_t::node_t)); 51 | for (i = 0; i < N; ++i) { 52 | d.key = data[i]; d.value = i; 53 | if (h->search(d) == 0) { h->insert(d); ++n; } 54 | else { h->erase(d); --n; } 55 | } 56 | delete h; 57 | return n; 58 | } 59 | 60 | int main(int argc, char *argv[]) 61 | { 62 | return udb_benchmark(argc, argv, test_int, test_str); 63 | } 64 | -------------------------------------------------------------------------------- /src/GM_avl/avltest.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "AVL.h" 3 | #include 4 | #include 5 | 6 | using namespace std; //introduces namespace std 7 | int main( void ) 8 | { 9 | int i; 10 | AVL junk; 11 | 12 | cout << "adding items\n"; 13 | 14 | for (i = 0; i < 20; ++i) 15 | { 16 | junk.Insert(i, i + 1); 17 | } 18 | 19 | cout << "creating iterator\n"; 20 | 21 | AVL::Iterator iter(&junk); 22 | 23 | bool more; 24 | short key = 3, item; 25 | 26 | more = iter.Find(key, item); 27 | cout << "Finding 3\n"; 28 | cout << "key - " << key << " item - " << item << "\n"; 29 | 30 | iter.GetFirst(key, item); 31 | 32 | cout << "Tree contains:\n"; 33 | 34 | more = iter.GetFirst(key, item); 35 | while (more) 36 | { 37 | cout << "key - " << key << " item - " << item << "\n"; 38 | more = iter.GetNext(key, item); 39 | } 40 | 41 | cout << "removing even keys\n"; 42 | 43 | for (i = 0; i < 20; i += 2) 44 | { 45 | junk.Remove(i); 46 | } 47 | 48 | more = iter.GetFirst(key, item); 49 | while (more) 50 | { 51 | cout << "key - " << key << " item - " << item << "\n"; 52 | more = iter.GetNext(key, item); 53 | } 54 | 55 | cout << "removing odd keys\n"; 56 | 57 | for (i = 1; i < 20; i += 2) 58 | { 59 | junk.Remove(i); 60 | } 61 | 62 | more = iter.GetFirst(key, item); 63 | while (more) 64 | { 65 | cout << "key - " << key << " item - " << item << "\n"; 66 | more = iter.GetNext(key, item); 67 | } 68 | 69 | cout << "done\n"; 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /src/libavl_avl/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include "avl.h" 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | int int_cmp(const void *_a, const void *_b, void *p) 18 | { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return (a->key > b->key) - (a->key < b->key); 22 | } 23 | int str_cmp(const void *a, const void *b, void *p) 24 | { 25 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 26 | } 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i; 31 | intmap_t *d, *r; 32 | struct avl_table *h; 33 | h = avl_create(int_cmp, 0, 0); 34 | for (i = 0; i < N; ++i) { 35 | d = (intmap_t*)malloc(sizeof(intmap_t)); 36 | d->key = data[i]; d->value = i; 37 | if (avl_find(h, d) == 0) avl_insert(h, d); 38 | else { 39 | r = avl_delete(h, d); 40 | free(d); free(r); 41 | } 42 | } 43 | return avl_count(h); 44 | } 45 | int test_str(int N, char * const *data) 46 | { 47 | int i; 48 | strmap_t *d, *r; 49 | struct avl_table *h; 50 | h = avl_create(str_cmp, 0, 0); 51 | for (i = 0; i < N; ++i) { 52 | d = (strmap_t*)malloc(sizeof(strmap_t)); 53 | d->key = data[i]; d->value = i; 54 | if (avl_find(h, d) == 0) avl_insert(h, d); 55 | else { 56 | r = avl_delete(h, d); 57 | free(d); free(r); 58 | } 59 | } 60 | return avl_count(h); 61 | } 62 | 63 | int main(int argc, char *argv[]) 64 | { 65 | return udb_benchmark(argc, argv, test_int, test_str); 66 | } 67 | -------------------------------------------------------------------------------- /src/libavl_avl_cpp/test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include "avl.hh" 7 | 8 | struct int_cmp { 9 | inline int operator () (unsigned a, unsigned b) { 10 | return (a > b) - (a < b); 11 | } 12 | }; 13 | 14 | struct str_cmp { 15 | inline int operator () (const char *a, const char *b) { 16 | return strcmp(a, b); 17 | } 18 | }; 19 | 20 | typedef avlmap_t intmap_t; 21 | typedef avlmap_t strmap_t; 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | int i, ret; 26 | intmap_t *h; 27 | intmap_t::node_t *p; 28 | printf("[test_int] node size: %zu\n", sizeof(intmap_t::node_t)); 29 | h = new intmap_t; 30 | for (i = 0; i < N; ++i) { 31 | p = h->find(data[i]); 32 | if (p == 0) { 33 | p = h->insert(data[i]); 34 | p->value = i; 35 | } else { 36 | p = h->erase(data[i]); 37 | free(p); 38 | } 39 | } 40 | ret = h->count; 41 | delete h; 42 | return ret; 43 | } 44 | int test_str(int N, char * const *data) 45 | { 46 | int i, ret; 47 | strmap_t *h; 48 | strmap_t::node_t *p; 49 | printf("[test_int] node size: %zu\n", sizeof(strmap_t::node_t)); 50 | h = new strmap_t; 51 | for (i = 0; i < N; ++i) { 52 | p = h->find(data[i]); 53 | if (p == 0) { 54 | p = h->insert(data[i]); 55 | p->value = i; 56 | } else { 57 | p = h->erase(data[i]); 58 | free(p); 59 | } 60 | } 61 | ret = h->count; 62 | delete h; 63 | return ret; 64 | } 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | return udb_benchmark(argc, argv, test_int, test_str); 69 | } 70 | -------------------------------------------------------------------------------- /src/libavl_avl_cpp/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include "avl.hh" 7 | 8 | struct int_cmp { 9 | inline int operator () (unsigned a, unsigned b) { 10 | return (a > b) - (a < b); 11 | } 12 | }; 13 | 14 | struct str_cmp { 15 | inline int operator () (const char *a, const char *b) { 16 | return strcmp(a, b); 17 | } 18 | }; 19 | 20 | typedef avlmap_t intmap_t; 21 | typedef avlmap_t strmap_t; 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | int i, ret; 26 | intmap_t *h; 27 | intmap_t::node_t *p; 28 | printf("[test_int] node size: %lu\n", sizeof(intmap_t::node_t)); 29 | h = new intmap_t; 30 | for (i = 0; i < N; ++i) { 31 | p = h->find(data[i]); 32 | if (p == 0) { 33 | p = h->insert(data[i]); 34 | p->value = i; 35 | } else { 36 | p = h->erase(data[i]); 37 | free(p); 38 | } 39 | } 40 | ret = h->count; 41 | delete h; 42 | return ret; 43 | } 44 | int test_str(int N, char * const *data) 45 | { 46 | int i, ret; 47 | strmap_t *h; 48 | strmap_t::node_t *p; 49 | printf("[test_int] node size: %lu\n", sizeof(strmap_t::node_t)); 50 | h = new strmap_t; 51 | for (i = 0; i < N; ++i) { 52 | p = h->find(data[i]); 53 | if (p == 0) { 54 | p = h->insert(data[i]); 55 | p->value = i; 56 | } else { 57 | p = h->erase(data[i]); 58 | free(p); 59 | } 60 | } 61 | ret = h->count; 62 | delete h; 63 | return ret; 64 | } 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | return udb_benchmark(argc, argv, test_int, test_str); 69 | } 70 | -------------------------------------------------------------------------------- /src/libavl_rb_cpp/test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include "rb.hh" 7 | 8 | struct int_cmp { 9 | inline int operator () (unsigned a, unsigned b) { 10 | return (a > b) - (a < b); 11 | } 12 | }; 13 | 14 | struct str_cmp { 15 | inline int operator () (const char *a, const char *b) { 16 | return strcmp(a, b); 17 | } 18 | }; 19 | 20 | typedef rbmap_t intmap_t; 21 | typedef rbmap_t strmap_t; 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | int i, ret; 26 | intmap_t *h; 27 | intmap_t::node_t *p; 28 | printf("[test_int] node size: %zu\n", sizeof(intmap_t::node_t)); 29 | h = new intmap_t; 30 | for (i = 0; i < N; ++i) { 31 | p = h->find(data[i]); 32 | if (p == 0) { 33 | p = h->insert(data[i], &ret); 34 | p->value = i; 35 | } else { 36 | p = h->erase(data[i]); 37 | free(p); 38 | } 39 | } 40 | ret = h->count; 41 | delete h; 42 | return ret; 43 | } 44 | int test_str(int N, char * const *data) 45 | { 46 | int i, ret; 47 | strmap_t *h; 48 | strmap_t::node_t *p; 49 | printf("[test_int] node size: %zu\n", sizeof(strmap_t::node_t)); 50 | h = new strmap_t; 51 | for (i = 0; i < N; ++i) { 52 | p = h->find(data[i]); 53 | if (p == 0) { 54 | p = h->insert(data[i], &ret); 55 | p->value = i; 56 | } else { 57 | p = h->erase(data[i]); 58 | free(p); 59 | } 60 | } 61 | ret = h->count; 62 | delete h; 63 | return ret; 64 | } 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | return udb_benchmark(argc, argv, test_int, test_str); 69 | } 70 | -------------------------------------------------------------------------------- /src/libavl_rb_cpp2/test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include "rb.hh" 7 | 8 | struct int_cmp { 9 | inline int operator () (unsigned a, unsigned b) { 10 | return (a > b) - (a < b); 11 | } 12 | }; 13 | 14 | struct str_cmp { 15 | inline int operator () (const char *a, const char *b) { 16 | return strcmp(a, b); 17 | } 18 | }; 19 | 20 | typedef rbmap_t intmap_t; 21 | typedef rbmap_t strmap_t; 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | int i, ret; 26 | intmap_t *h; 27 | intmap_t::node_t *p; 28 | printf("[test_int] node size: %zu\n", sizeof(intmap_t::node_t)); 29 | h = new intmap_t; 30 | for (i = 0; i < N; ++i) { 31 | p = h->find(data[i]); 32 | if (p == 0) { 33 | p = h->insert(data[i], &ret); 34 | p->value = i; 35 | } else { 36 | p = h->erase(data[i]); 37 | free(p); 38 | } 39 | } 40 | ret = h->count; 41 | delete h; 42 | return ret; 43 | } 44 | int test_str(int N, char * const *data) 45 | { 46 | int i, ret; 47 | strmap_t *h; 48 | strmap_t::node_t *p; 49 | printf("[test_int] node size: %zu\n", sizeof(strmap_t::node_t)); 50 | h = new strmap_t; 51 | for (i = 0; i < N; ++i) { 52 | p = h->find(data[i]); 53 | if (p == 0) { 54 | p = h->insert(data[i], &ret); 55 | p->value = i; 56 | } else { 57 | p = h->erase(data[i]); 58 | free(p); 59 | } 60 | } 61 | ret = h->count; 62 | delete h; 63 | return ret; 64 | } 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | return udb_benchmark(argc, argv, test_int, test_str); 69 | } 70 | -------------------------------------------------------------------------------- /src/libavl_rb_cpp/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include "rb.hh" 7 | 8 | struct int_cmp { 9 | inline int operator () (unsigned a, unsigned b) { 10 | return (a > b) - (a < b); 11 | } 12 | }; 13 | 14 | struct str_cmp { 15 | inline int operator () (const char *a, const char *b) { 16 | return strcmp(a, b); 17 | } 18 | }; 19 | 20 | typedef rbmap_t intmap_t; 21 | typedef rbmap_t strmap_t; 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | int i, ret; 26 | intmap_t *h; 27 | intmap_t::node_t *p; 28 | printf("[test_int] node size: %lu\n", sizeof(intmap_t::node_t)); 29 | h = new intmap_t; 30 | for (i = 0; i < N; ++i) { 31 | p = h->find(data[i]); 32 | if (p == 0) { 33 | p = h->insert(data[i], &ret); 34 | p->value = i; 35 | } else { 36 | p = h->erase(data[i]); 37 | free(p); 38 | } 39 | } 40 | ret = h->count; 41 | delete h; 42 | return ret; 43 | } 44 | int test_str(int N, char * const *data) 45 | { 46 | int i, ret; 47 | strmap_t *h; 48 | strmap_t::node_t *p; 49 | printf("[test_int] node size: %lu\n", sizeof(strmap_t::node_t)); 50 | h = new strmap_t; 51 | for (i = 0; i < N; ++i) { 52 | p = h->find(data[i]); 53 | if (p == 0) { 54 | p = h->insert(data[i], &ret); 55 | p->value = i; 56 | } else { 57 | p = h->erase(data[i]); 58 | free(p); 59 | } 60 | } 61 | ret = h->count; 62 | delete h; 63 | return ret; 64 | } 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | return udb_benchmark(argc, argv, test_int, test_str); 69 | } 70 | -------------------------------------------------------------------------------- /src/libavl_rb_cpp2/test.cc.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include "rb.hh" 7 | 8 | struct int_cmp { 9 | inline int operator () (unsigned a, unsigned b) { 10 | return (a > b) - (a < b); 11 | } 12 | }; 13 | 14 | struct str_cmp { 15 | inline int operator () (const char *a, const char *b) { 16 | return strcmp(a, b); 17 | } 18 | }; 19 | 20 | typedef rbmap_t intmap_t; 21 | typedef rbmap_t strmap_t; 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | int i, ret; 26 | intmap_t *h; 27 | intmap_t::node_t *p; 28 | printf("[test_int] node size: %lu\n", sizeof(intmap_t::node_t)); 29 | h = new intmap_t; 30 | for (i = 0; i < N; ++i) { 31 | p = h->find(data[i]); 32 | if (p == 0) { 33 | p = h->insert(data[i], &ret); 34 | p->value = i; 35 | } else { 36 | p = h->erase(data[i]); 37 | free(p); 38 | } 39 | } 40 | ret = h->count; 41 | delete h; 42 | return ret; 43 | } 44 | int test_str(int N, char * const *data) 45 | { 46 | int i, ret; 47 | strmap_t *h; 48 | strmap_t::node_t *p; 49 | printf("[test_int] node size: %lu\n", sizeof(strmap_t::node_t)); 50 | h = new strmap_t; 51 | for (i = 0; i < N; ++i) { 52 | p = h->find(data[i]); 53 | if (p == 0) { 54 | p = h->insert(data[i], &ret); 55 | p->value = i; 56 | } else { 57 | p = h->erase(data[i]); 58 | free(p); 59 | } 60 | } 61 | ret = h->count; 62 | delete h; 63 | return ret; 64 | } 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | return udb_benchmark(argc, argv, test_int, test_str); 69 | } 70 | -------------------------------------------------------------------------------- /src/kbtree/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "benchmark.h" 3 | 4 | typedef struct { 5 | unsigned key; 6 | int value; 7 | } intmap_t; 8 | 9 | typedef struct { 10 | char *key; 11 | int value; 12 | } strmap_t; 13 | 14 | #define __intcmp(a, b) (((a).key > (b).key) - ((a).key < (b).key)) 15 | #define __strcmp(a, b) strcmp((a).key, (b).key) 16 | 17 | #include "kbtree.h" 18 | KBTREE_INIT(int, intmap_t, __intcmp) 19 | KBTREE_INIT(str, strmap_t, __strcmp) 20 | 21 | int test_int(int N, const unsigned *data) 22 | { 23 | int i, ret; 24 | intmap_t d; 25 | kbtree_t(int) *h; 26 | h = kb_init(int, KB_DEFAULT_SIZE); 27 | for (i = 0; i < N; ++i) { 28 | d.key = data[i]; d.value = i; 29 | if (kb_getp(int, h, &d) == 0) kb_putp(int, h, &d); 30 | else kb_delp(int, h, &d); 31 | } 32 | ret = (int)kb_size(h); 33 | if (0) { 34 | unsigned xor = 0; 35 | #define traf(k) (xor ^= (k)->value) 36 | __kb_traverse(intmap_t, h, traf); 37 | printf("%u\n", xor); 38 | } 39 | kb_destroy(int, h); 40 | return ret; 41 | } 42 | int test_str(int N, char * const *data) 43 | { 44 | int i, ret; 45 | strmap_t d; 46 | kbtree_t(str) *h; 47 | h = kb_init(str, KB_DEFAULT_SIZE); 48 | for (i = 0; i < N; ++i) { 49 | d.key = data[i]; d.value = i; 50 | if (kb_getp(str, h, &d) == 0) kb_putp(str, h, &d); 51 | else kb_delp(str, h, &d); 52 | } 53 | ret = (int)kb_size(h); 54 | if (0) { 55 | unsigned xor = 0; 56 | __kb_traverse(strmap_t, h, traf); 57 | printf("%u\n", xor); 58 | } 59 | kb_destroy(str, h); 60 | return ret; 61 | } 62 | 63 | int main(int argc, char *argv[]) 64 | { 65 | return udb_benchmark(argc, argv, test_int, test_str); 66 | } 67 | -------------------------------------------------------------------------------- /src/google_dense/google/sparsehash/sparseconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NOTE: This file is for internal use only. 3 | * Do not use these #defines in your own program! 4 | */ 5 | 6 | /* Namespace for Google classes */ 7 | #define GOOGLE_NAMESPACE ::google 8 | 9 | /* the location of / */ 10 | #define HASH_FUN_H 11 | 12 | /* the namespace of hash_map/hash_set */ 13 | #define HASH_NAMESPACE __gnu_cxx 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #define HAVE_INTTYPES_H 1 17 | 18 | /* Define to 1 if the system has the type `long long'. */ 19 | #define HAVE_LONG_LONG 1 20 | 21 | /* Define to 1 if you have the `memcpy' function. */ 22 | #define HAVE_MEMCPY 1 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #define HAVE_STDINT_H 1 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #define HAVE_SYS_TYPES_H 1 29 | 30 | /* Define to 1 if the system has the type `uint16_t'. */ 31 | #define HAVE_UINT16_T 1 32 | 33 | /* Define to 1 if the system has the type `u_int16_t'. */ 34 | #define HAVE_U_INT16_T 1 35 | 36 | /* Define to 1 if the system has the type `__uint16'. */ 37 | /* #undef HAVE___UINT16 */ 38 | 39 | /* The system-provided hash function including the namespace. */ 40 | #define SPARSEHASH_HASH HASH_NAMESPACE::hash 41 | 42 | /* the namespace where STL code like vector<> is defined */ 43 | #define STL_NAMESPACE std 44 | 45 | /* Stops putting the code inside the Google namespace */ 46 | #define _END_GOOGLE_NAMESPACE_ } 47 | 48 | /* Puts following code inside the Google namespace */ 49 | #define _START_GOOGLE_NAMESPACE_ namespace google { 50 | -------------------------------------------------------------------------------- /src/google_sparse/google/sparsehash/sparseconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NOTE: This file is for internal use only. 3 | * Do not use these #defines in your own program! 4 | */ 5 | 6 | /* Namespace for Google classes */ 7 | #define GOOGLE_NAMESPACE ::google 8 | 9 | /* the location of / */ 10 | #define HASH_FUN_H 11 | 12 | /* the namespace of hash_map/hash_set */ 13 | #define HASH_NAMESPACE __gnu_cxx 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #define HAVE_INTTYPES_H 1 17 | 18 | /* Define to 1 if the system has the type `long long'. */ 19 | #define HAVE_LONG_LONG 1 20 | 21 | /* Define to 1 if you have the `memcpy' function. */ 22 | #define HAVE_MEMCPY 1 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #define HAVE_STDINT_H 1 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #define HAVE_SYS_TYPES_H 1 29 | 30 | /* Define to 1 if the system has the type `uint16_t'. */ 31 | #define HAVE_UINT16_T 1 32 | 33 | /* Define to 1 if the system has the type `u_int16_t'. */ 34 | #define HAVE_U_INT16_T 1 35 | 36 | /* Define to 1 if the system has the type `__uint16'. */ 37 | /* #undef HAVE___UINT16 */ 38 | 39 | /* The system-provided hash function including the namespace. */ 40 | #define SPARSEHASH_HASH HASH_NAMESPACE::hash 41 | 42 | /* the namespace where STL code like vector<> is defined */ 43 | #define STL_NAMESPACE std 44 | 45 | /* Stops putting the code inside the Google namespace */ 46 | #define _END_GOOGLE_NAMESPACE_ } 47 | 48 | /* Puts following code inside the Google namespace */ 49 | #define _START_GOOGLE_NAMESPACE_ namespace google { 50 | -------------------------------------------------------------------------------- /src/libavl_rb/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include "rb.h" 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | int int_cmp(const void *_a, const void *_b, void *p) 18 | { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return (a->key > b->key) - (a->key < b->key); 22 | } 23 | int str_cmp(const void *a, const void *b, void *p) 24 | { 25 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 26 | } 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i, n = 0; 31 | intmap_t *d, *r; 32 | struct rb_table *h; 33 | h = rb_create(int_cmp, 0, 0); 34 | for (i = 0; i < N; ++i) { 35 | d = (intmap_t*)malloc(sizeof(intmap_t)); 36 | d->key = data[i]; d->value = i; 37 | if (rb_find(h, d) == 0) { 38 | rb_insert(h, d); 39 | ++n; 40 | } else { 41 | r = rb_delete(h, d); 42 | free(d); free(r); 43 | --n; 44 | } 45 | } 46 | return n; 47 | } 48 | int test_str(int N, char * const *data) 49 | { 50 | int i, n = 0; 51 | strmap_t *d, *r; 52 | struct rb_table *h; 53 | h = rb_create(str_cmp, 0, 0); 54 | for (i = 0; i < N; ++i) { 55 | d = (strmap_t*)malloc(sizeof(strmap_t)); 56 | d->key = data[i]; d->value = i; 57 | if (rb_find(h, d) == 0) { 58 | rb_insert(h, d); 59 | ++n; 60 | } else { 61 | r = rb_delete(h, d); 62 | free(d); free(r); 63 | --n; 64 | } 65 | } 66 | return n; 67 | } 68 | 69 | int main(int argc, char *argv[]) 70 | { 71 | return udb_benchmark(argc, argv, test_int, test_str); 72 | } 73 | -------------------------------------------------------------------------------- /src/JG_btree/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include "btree.h" 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | int int_cmp(void *_a, void *_b) 18 | { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return (a->key > b->key) - (a->key < b->key); 22 | } 23 | int str_cmp(void *a, void *b) 24 | { 25 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 26 | } 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i, n = 0; 31 | intmap_t d, *r; 32 | struct btree *h; 33 | h = bt_create(int_cmp, BT_SIZEDEF); 34 | for (i = 0; i < N; ++i) { 35 | d.key = data[i]; 36 | if ((r = bt_find(h, &d)) == 0) { 37 | r = (intmap_t*)malloc(sizeof(intmap_t)); 38 | r->key = data[i]; r->value = i; 39 | bt_insert(h, r); 40 | ++n; 41 | } else { 42 | bt_delete(h, r); 43 | free(r); 44 | --n; 45 | } 46 | } 47 | return n; 48 | } 49 | int test_str(int N, char * const *data) 50 | { 51 | int i, n = 0; 52 | strmap_t d, *r; 53 | struct btree *h; 54 | h = bt_create(str_cmp, BT_SIZEDEF); 55 | for (i = 0; i < N; ++i) { 56 | d.key = data[i]; 57 | if ((r = bt_find(h, &d)) == 0) { 58 | r = (strmap_t*)malloc(sizeof(strmap_t)); 59 | r->key = data[i]; r->value = i; 60 | bt_insert(h, r); 61 | ++n; 62 | } else { 63 | bt_delete(h, r); 64 | free(r); 65 | --n; 66 | } 67 | } 68 | return n; 69 | } 70 | 71 | int main(int argc, char *argv[]) 72 | { 73 | return udb_benchmark(argc, argv, test_int, test_str); 74 | } 75 | -------------------------------------------------------------------------------- /src/_gdsl_rb/test.c.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | int int_cmp(const void *_a, const void *_b) 18 | { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return (a->key > b->key) - (a->key < b->key); 22 | } 23 | int str_cmp(const void *a, const void *b) 24 | { 25 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 26 | } 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i, n = 0, ret; 31 | intmap_t *d, *r; 32 | gdsl_rbtree_t *h; 33 | h = gdsl_rbtree_alloc(0, 0, 0, int_cmp); 34 | for (i = 0; i < N; ++i) { 35 | d = (intmap_t*)malloc(sizeof(intmap_t)); 36 | d->key = data[i]; d->value = i; 37 | gdsl_rbtree_insert(h, d, &ret); 38 | if (ret != 2) { 39 | r = gdsl_rbtree_remove(h, d); 40 | free(d); free(r); 41 | --n; 42 | } else ++n; 43 | } 44 | return n; 45 | } 46 | int test_str(int N, char * const *data) 47 | { 48 | int i, n = 0, ret; 49 | strmap_t *d, *r; 50 | gdsl_rbtree_t *h; 51 | h = gdsl_rbtree_alloc(0, 0, 0, str_cmp); 52 | for (i = 0; i < N; ++i) { 53 | d = (strmap_t*)malloc(sizeof(strmap_t)); 54 | d->key = data[i]; d->value = i; 55 | gdsl_rbtree_insert(h, d, &ret); 56 | if (ret != 2) { 57 | r = gdsl_rbtree_remove(h, d); 58 | free(d); free(r); 59 | --n; 60 | } else ++n; 61 | } 62 | return n; 63 | } 64 | 65 | int main(int argc, char *argv[]) 66 | { 67 | return udb_benchmark(argc, argv, test_int, test_str); 68 | } 69 | -------------------------------------------------------------------------------- /src/libavl_bst/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include "bst.h" 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | int int_cmp(const void *_a, const void *_b, void *p) 18 | { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return (a->key > b->key) - (a->key < b->key); 22 | } 23 | int str_cmp(const void *a, const void *b, void *p) 24 | { 25 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 26 | } 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i, n = 0; 31 | intmap_t *d, *r; 32 | struct bst_table *h; 33 | h = bst_create(int_cmp, 0, 0); 34 | for (i = 0; i < N; ++i) { 35 | d = (intmap_t*)malloc(sizeof(intmap_t)); 36 | d->key = data[i]; d->value = i; 37 | if (bst_find(h, d) == 0) { 38 | bst_insert(h, d); 39 | ++n; 40 | } else { 41 | r = bst_delete(h, d); 42 | free(d); free(r); 43 | --n; 44 | } 45 | } 46 | return n; 47 | } 48 | int test_str(int N, char * const *data) 49 | { 50 | int i, n = 0; 51 | strmap_t *d, *r; 52 | struct bst_table *h; 53 | h = bst_create(str_cmp, 0, 0); 54 | for (i = 0; i < N; ++i) { 55 | d = (strmap_t*)malloc(sizeof(strmap_t)); 56 | d->key = data[i]; d->value = i; 57 | if (bst_find(h, d) == 0) { 58 | bst_insert(h, d); 59 | ++n; 60 | } else { 61 | r = bst_delete(h, d); 62 | free(d); free(r); 63 | --n; 64 | } 65 | } 66 | return n; 67 | } 68 | 69 | int main(int argc, char *argv[]) 70 | { 71 | return udb_benchmark(argc, argv, test_int, test_str); 72 | } 73 | -------------------------------------------------------------------------------- /src/libavl_prb/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include "prb.h" 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | int int_cmp(const void *_a, const void *_b, void *p) 18 | { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return (a->key > b->key) - (a->key < b->key); 22 | } 23 | int str_cmp(const void *a, const void *b, void *p) 24 | { 25 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 26 | } 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i, n = 0; 31 | intmap_t *d, *r; 32 | struct prb_table *h; 33 | h = prb_create(int_cmp, 0, 0); 34 | for (i = 0; i < N; ++i) { 35 | d = (intmap_t*)malloc(sizeof(intmap_t)); 36 | d->key = data[i]; d->value = i; 37 | if (prb_find(h, d) == 0) { 38 | prb_insert(h, d); 39 | ++n; 40 | } else { 41 | r = prb_delete(h, d); 42 | free(d); free(r); 43 | --n; 44 | } 45 | } 46 | return n; 47 | } 48 | int test_str(int N, char * const *data) 49 | { 50 | int i, n = 0; 51 | strmap_t *d, *r; 52 | struct prb_table *h; 53 | h = prb_create(str_cmp, 0, 0); 54 | for (i = 0; i < N; ++i) { 55 | d = (strmap_t*)malloc(sizeof(strmap_t)); 56 | d->key = data[i]; d->value = i; 57 | if (prb_find(h, d) == 0) { 58 | prb_insert(h, d); 59 | ++n; 60 | } else { 61 | r = prb_delete(h, d); 62 | free(d); free(r); 63 | --n; 64 | } 65 | } 66 | return n; 67 | } 68 | 69 | int main(int argc, char *argv[]) 70 | { 71 | return udb_benchmark(argc, argv, test_int, test_str); 72 | } 73 | -------------------------------------------------------------------------------- /src/_gdsl_rb/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include 6 | 7 | typedef struct { 8 | unsigned key; 9 | int value; 10 | } intmap_t; 11 | 12 | typedef struct { 13 | char *key; 14 | int value; 15 | } strmap_t; 16 | 17 | int int_cmp(const void *_a, const void *_b) 18 | { 19 | intmap_t *a = (intmap_t*)_a; 20 | intmap_t *b = (intmap_t*)_b; 21 | return (a->key > b->key) - (a->key < b->key); 22 | } 23 | int str_cmp(const void *a, const void *b) 24 | { 25 | return strcmp(((strmap_t*)a)->key, ((strmap_t*)b)->key); 26 | } 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i, n = 0, ret; 31 | intmap_t *d, *r; 32 | gdsl_rbtree_t h; 33 | h = gdsl_rbtree_alloc(0, 0, 0, (gdsl_compare_func_t) int_cmp); 34 | for (i = 0; i < N; ++i) { 35 | d = (intmap_t*)malloc(sizeof(intmap_t)); 36 | d->key = data[i]; d->value = i; 37 | gdsl_rbtree_insert(h, d, &ret); 38 | if (ret != 2) { 39 | r = gdsl_rbtree_remove(h, d); 40 | free(d); free(r); 41 | --n; 42 | } else ++n; 43 | } 44 | return n; 45 | } 46 | int test_str(int N, char * const *data) 47 | { 48 | int i, n = 0, ret; 49 | strmap_t *d, *r; 50 | gdsl_rbtree_t h; 51 | h = gdsl_rbtree_alloc(0, 0, 0, (gdsl_compare_func_t) str_cmp); 52 | for (i = 0; i < N; ++i) { 53 | d = (strmap_t*)malloc(sizeof(strmap_t)); 54 | d->key = data[i]; d->value = i; 55 | gdsl_rbtree_insert(h, d, &ret); 56 | if (ret != 2) { 57 | r = gdsl_rbtree_remove(h, d); 58 | free(d); free(r); 59 | --n; 60 | } else ++n; 61 | } 62 | return n; 63 | } 64 | 65 | int main(int argc, char *argv[]) 66 | { 67 | return udb_benchmark(argc, argv, test_int, test_str); 68 | } 69 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/fixed_array.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FIXED_ARRAY_H 2 | #define RDESTL_FIXED_ARRAY_H 3 | 4 | #include "rdestl/algorithm.h" 5 | 6 | namespace rde 7 | { 8 | //============================================================================= 9 | template 10 | class fixed_array 11 | { 12 | typedef char ERR_N_MustBeBiggerThanZero[N > 0 ? 1 : -1]; 13 | public: 14 | typedef T value_type; 15 | typedef T* iterator; 16 | typedef const T* const_iterator; 17 | typedef size_t size_type; 18 | 19 | fixed_array() {/**/} 20 | fixed_array(const T array[N]) 21 | { 22 | rde::copy_n(&array[0], N, m_data); 23 | } 24 | // copy ctor/dtor generated 25 | // assignment op generated 26 | 27 | iterator begin() { return &m_data[0]; } 28 | const_iterator begin() const { return &m_data[0]; } 29 | iterator end() { return begin() + N; } 30 | const_iterator end() const { return begin() + N; } 31 | size_type size() const { return N; } 32 | T* data() { return &m_data[0]; } 33 | const T* data() const { return &m_data[0]; } 34 | 35 | const T& front() const { return *begin(); } 36 | T& front() { return *begin(); } 37 | const T& back() const { return *(end() - 1); } 38 | T& back() { return *(end() - 1); } 39 | 40 | RDE_FORCEINLINE T& operator[](size_type i) 41 | { 42 | RDE_ASSERT(i < size()); 43 | return m_data[i]; 44 | } 45 | RDE_FORCEINLINE const T& operator[](size_type i) const 46 | { 47 | RDE_ASSERT(i < size()); 48 | return m_data[i]; 49 | } 50 | 51 | private: 52 | T m_data[N]; 53 | }; 54 | 55 | } // rde 56 | 57 | //----------------------------------------------------------------------------- 58 | #endif // #ifndef RDESTL_FIXED_ARRAY_H 59 | 60 | -------------------------------------------------------------------------------- /src/rdestl/new.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- forwarding header. 2 | // Copyright (C) 2000 Free Software Foundation 3 | 4 | // This file is part of GCC. 5 | // 6 | // GCC is free software; you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation; either version 2, or (at your option) 9 | // any later version. 10 | // 11 | // GCC is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with GCC; see the file COPYING. If not, write to 18 | // the Free Software Foundation, 51 Franklin Street, Fifth Floor, 19 | // Boston, MA 02110-1301, USA. 20 | 21 | // As a special exception, you may use this file as part of a free software 22 | // library without restriction. Specifically, if other files instantiate 23 | // templates or use macros or inline functions from this file, or you compile 24 | // this file and link it with other files to produce an executable, this 25 | // file does not by itself cause the resulting executable to be covered by 26 | // the GNU General Public License. This exception does not however 27 | // invalidate any other reasons why the executable file might be covered by 28 | // the GNU General Public License. 29 | 30 | #ifndef _BACKWARD_NEW_H 31 | #define _BACKWARD_NEW_H 1 32 | 33 | #include "backward_warning.h" 34 | #include 35 | 36 | using std::bad_alloc; 37 | using std::nothrow_t; 38 | using std::nothrow; 39 | using std::new_handler; 40 | using std::set_new_handler; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/fixed_substring.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FIXED_SUBSTRING_H 2 | #define RDESTL_FIXED_SUBSTRING_H 3 | 4 | #include "rdestl/fixed_array.h" 5 | #include "rdestl/string_utils.h" 6 | 7 | namespace rde 8 | { 9 | // "Substring" of fixed size. 10 | // Cannot grow. 11 | // Never allocates memory. 12 | // !! WORK IN PROGRESS 13 | template 14 | class fixed_substring : private fixed_array 15 | { 16 | typedef fixed_array Base; 17 | public: 18 | typedef E value_type; 19 | typedef int size_type; 20 | 21 | fixed_substring() 22 | { 23 | data()[0] = value_type(0); 24 | } 25 | explicit fixed_substring(const value_type* str) 26 | { 27 | assign(str); 28 | } 29 | 30 | using Base::operator[]; 31 | using Base::data; 32 | 33 | void assign(const value_type* str) 34 | { 35 | RDE_ASSERT(str != data()); 36 | const size_type len = (size_type)rde::strlen(str); 37 | const size_type toCopy = len < N ? len : N; 38 | Sys::MemCpy(data(), str, toCopy * sizeof(value_type)); 39 | data()[toCopy] = value_type(0); 40 | } 41 | void append(const value_type* str) 42 | { 43 | const size_type strLen = (size_type)rde::strlen(str); 44 | const size_type ourLen = (size_type)rde::strlen(data()); 45 | size_type toAppend = strLen; 46 | if (ourLen + toAppend > N) 47 | toAppend = N - ourLen; 48 | Sys::MemCpy(data() + ourLen, str, toAppend * sizeof(value_type)); 49 | data()[ourLen + toAppend] = value_type(0); 50 | } 51 | 52 | bool empty() const 53 | { 54 | // @todo: consider caching string len 55 | return rde::strlen(data()) == 0; 56 | } 57 | bool operator==(const fixed_substring& rhs) const 58 | { 59 | return rde::strcompare(data(), rhs.data()) == 0; 60 | } 61 | }; 62 | 63 | } // rde 64 | 65 | #endif // #ifndef RDESTL_FIXED_SUBSTRING_H 66 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_STACK_H 2 | #define RDESTL_STACK_H 3 | 4 | #include "rdestl/vector.h" 5 | 6 | namespace rde 7 | { 8 | // Stack implemented on top of another container (vector by default). 9 | template > 11 | class stack 12 | { 13 | public: 14 | typedef TContainer container_type; 15 | typedef typename TContainer::value_type value_type; 16 | typedef typename TContainer::size_type size_type; 17 | typedef TAllocator allocator_type; 18 | 19 | explicit stack(const allocator_type& allocator = allocator_type()) 20 | : m_container(allocator) 21 | { 22 | } 23 | stack(const stack& rhs, const allocator_type& allocator = allocator_type()) 24 | : m_container(rhs, allocator) 25 | { 26 | } 27 | 28 | // @note Doesnt copy allocator from rhs. 29 | stack& operator=(const stack& rhs) 30 | { 31 | if (&rhs != this) 32 | { 33 | m_container = rhs.m_container; 34 | } 35 | return *this; 36 | } 37 | 38 | void push(const value_type& v) 39 | { 40 | m_container.push_back(v); 41 | } 42 | void pop() 43 | { 44 | m_container.pop_back(); 45 | } 46 | value_type& top() { return m_container.back(); } 47 | const value_type& top() const { return m_container.back(); } 48 | 49 | // @extension 50 | void clear() { m_container.clear(); } 51 | 52 | bool empty() const { return m_container.empty(); } 53 | size_type size() const { return m_container.size(); } 54 | 55 | const allocator_type& get_allocator() const 56 | { 57 | return m_container.get_allocator(); 58 | } 59 | void set_allocator(const allocator_type& allocator) 60 | { 61 | m_container.set_allocator(allocator); 62 | } 63 | 64 | private: 65 | TContainer m_container; 66 | }; 67 | 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/_glib_hash/test.c.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include 7 | 8 | /* 9 | int test_int(int N, const unsigned *data) 10 | { 11 | int i, val = 11, ret; 12 | GHashTable *h; 13 | h = g_hash_table_new(g_int_hash, g_int_equal); 14 | for (i = 0; i < N; ++i) { 15 | if (!g_hash_table_steal(h, &data[i])) { 16 | g_hash_table_insert(h, &data[i], &val); 17 | } 18 | } 19 | ret = g_hash_table_size(h); 20 | g_hash_table_destroy(h); 21 | return ret; 22 | } 23 | int test_str(int N, char * const *data) 24 | { 25 | int i, val = 11, ret; 26 | GHashTable *h; 27 | h = g_hash_table_new(g_str_hash, g_str_equal); 28 | for (i = 0; i < N; ++i) { 29 | if (!g_hash_table_steal(h, data[i])) { 30 | g_hash_table_insert(h, data[i], &val); 31 | } 32 | } 33 | ret = g_hash_table_size(h); 34 | g_hash_table_destroy(h); 35 | return ret; 36 | } 37 | */ 38 | int test_int(int N, const unsigned *data) 39 | { 40 | int i, ret, *p; 41 | GHashTable *h; 42 | h = g_hash_table_new_full(g_int_hash, g_int_equal, 0, free); 43 | for (i = 0; i < N; ++i) { 44 | if (!g_hash_table_remove(h, &data[i])) { 45 | p = (int*)malloc(sizeof(int)); 46 | *p = i; 47 | g_hash_table_insert(h, &data[i], p); 48 | } 49 | } 50 | ret = g_hash_table_size(h); 51 | g_hash_table_destroy(h); 52 | return ret; 53 | } 54 | int test_str(int N, char * const *data) 55 | { 56 | int i, ret, *p; 57 | GHashTable *h; 58 | h = g_hash_table_new_full(g_str_hash, g_str_equal, 0, free); 59 | for (i = 0; i < N; ++i) { 60 | if (!g_hash_table_remove(h, data[i])) { 61 | p = (int*)malloc(sizeof(int)); 62 | *p = i; 63 | g_hash_table_insert(h, data[i], p); 64 | } 65 | } 66 | ret = g_hash_table_size(h); 67 | g_hash_table_destroy(h); 68 | return ret; 69 | } 70 | 71 | int main(int argc, char *argv[]) 72 | { 73 | return udb_benchmark(argc, argv, test_int, test_str); 74 | } 75 | -------------------------------------------------------------------------------- /src/_glib_hash/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | 6 | #include 7 | 8 | /* 9 | int test_int(int N, const unsigned *data) 10 | { 11 | int i, val = 11, ret; 12 | GHashTable *h; 13 | h = g_hash_table_new(g_int_hash, g_int_equal); 14 | for (i = 0; i < N; ++i) { 15 | if (!g_hash_table_steal(h, &data[i])) { 16 | g_hash_table_insert(h, &data[i], &val); 17 | } 18 | } 19 | ret = g_hash_table_size(h); 20 | g_hash_table_destroy(h); 21 | return ret; 22 | } 23 | int test_str(int N, char * const *data) 24 | { 25 | int i, val = 11, ret; 26 | GHashTable *h; 27 | h = g_hash_table_new(g_str_hash, g_str_equal); 28 | for (i = 0; i < N; ++i) { 29 | if (!g_hash_table_steal(h, data[i])) { 30 | g_hash_table_insert(h, data[i], &val); 31 | } 32 | } 33 | ret = g_hash_table_size(h); 34 | g_hash_table_destroy(h); 35 | return ret; 36 | } 37 | */ 38 | int test_int(int N, const unsigned *data) 39 | { 40 | int i, ret, *p; 41 | GHashTable *h; 42 | h = g_hash_table_new_full(g_int_hash, g_int_equal, 0, free); 43 | for (i = 0; i < N; ++i) { 44 | if (!g_hash_table_remove(h, &data[i])) { 45 | p = (int*)malloc(sizeof(int)); 46 | *p = i; 47 | g_hash_table_insert(h, (unsigned *) &data[i], p); 48 | } 49 | } 50 | ret = g_hash_table_size(h); 51 | g_hash_table_destroy(h); 52 | return ret; 53 | } 54 | int test_str(int N, char * const *data) 55 | { 56 | int i, ret, *p; 57 | GHashTable *h; 58 | h = g_hash_table_new_full(g_str_hash, g_str_equal, 0, free); 59 | for (i = 0; i < N; ++i) { 60 | if (!g_hash_table_remove(h, data[i])) { 61 | p = (int*)malloc(sizeof(int)); 62 | *p = i; 63 | g_hash_table_insert(h, data[i], p); 64 | } 65 | } 66 | ret = g_hash_table_size(h); 67 | g_hash_table_destroy(h); 68 | return ret; 69 | } 70 | 71 | int main(int argc, char *argv[]) 72 | { 73 | return udb_benchmark(argc, argv, test_int, test_str); 74 | } 75 | -------------------------------------------------------------------------------- /src/JE_rb_new/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "benchmark.h" 6 | #include "rb.h" 7 | 8 | typedef struct intnode_s intnode_t; 9 | struct intnode_s { 10 | rb_node(intnode_t) link; 11 | unsigned key; 12 | int val; 13 | }; 14 | typedef rb_tree(intnode_t) inttree_t; 15 | static inline int int_cmp(intnode_t *a, intnode_t *b) { return (a->key > b->key) - (a->key < b->key); } 16 | 17 | typedef struct strnode_s strnode_t; 18 | struct strnode_s { 19 | rb_node(strnode_t) link; 20 | char *key; 21 | int val; 22 | }; 23 | typedef rb_tree(strnode_t) strtree_t; 24 | static inline int str_cmp(strnode_t *a, strnode_t *b) { return strcmp(a->key, b->key); } 25 | 26 | int test_int(int N, const unsigned *data) 27 | { 28 | inttree_t h; 29 | intnode_t d, *node; 30 | int i, n = 0; 31 | rb_new(intnode_t, link, &h); 32 | for (i = 0; i < N; ++i) { 33 | d.key = data[i]; 34 | rb_search(intnode_t, link, int_cmp, &h, &d, node); 35 | if (node) { 36 | rb_remove(intnode_t, link, int_cmp, &h, node); 37 | free(node); 38 | --n; 39 | } else { 40 | node = (intnode_t*)malloc(sizeof(intnode_t)); 41 | node->key = data[i]; node->val = i; 42 | rb_insert(intnode_t, link, int_cmp, &h, node); 43 | ++n; 44 | } 45 | } 46 | return n; 47 | } 48 | int test_str(int N, char * const *data) 49 | { 50 | strtree_t h; 51 | strnode_t d, *node; 52 | int i, n = 0; 53 | rb_new(strnode_t, link, &h); 54 | for (i = 0; i < N; ++i) { 55 | d.key = data[i]; 56 | rb_search(strnode_t, link, str_cmp, &h, &d, node); 57 | if (node) { 58 | rb_remove(strnode_t, link, str_cmp, &h, node); 59 | free(node); 60 | --n; 61 | } else { 62 | node = (strnode_t*)malloc(sizeof(strnode_t)); 63 | node->key = data[i]; node->val = i; 64 | rb_insert(strnode_t, link, str_cmp, &h, node); 65 | ++n; 66 | } 67 | } 68 | return n; 69 | } 70 | 71 | int main(int argc, char *argv[]) 72 | { 73 | return udb_benchmark(argc, argv, test_int, test_str); 74 | } 75 | -------------------------------------------------------------------------------- /src/JE_trp_hash/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "benchmark.h" 7 | #include "trp.h" 8 | 9 | typedef struct intnode_s intnode_t; 10 | struct intnode_s { 11 | trp_node(intnode_t) link; 12 | unsigned key; 13 | int val; 14 | }; 15 | static int int_cmp(intnode_t *a, intnode_t *b) { return (a->key > b->key) - (a->key < b->key); } 16 | typedef trp(intnode_t) inttree_t; 17 | trp_gen(static, inttree_, inttree_t, intnode_t, link, int_cmp); 18 | 19 | typedef struct strnode_s strnode_t; 20 | struct strnode_s { 21 | trp_node(strnode_t) link; 22 | char *key; 23 | int val; 24 | }; 25 | typedef trp(strnode_t) strtree_t; 26 | static int str_cmp(strnode_t *a, strnode_t *b) { return strcmp(a->key, b->key); } 27 | trp_gen(static, strtree_, strtree_t, strnode_t, link, str_cmp); 28 | 29 | int test_int(int N, const unsigned *data) 30 | { 31 | inttree_t h; 32 | intnode_t d, *node; 33 | int i, n = 0; 34 | inttree_new(&h, 11); 35 | for (i = 0; i < N; ++i) { 36 | d.key = data[i]; 37 | node = inttree_search(&h, &d); 38 | if (node) { 39 | inttree_remove(&h, node); 40 | free(node); 41 | --n; 42 | } else { 43 | node = (intnode_t*)malloc(sizeof(intnode_t)); 44 | node->key = data[i]; node->val = i; 45 | inttree_insert(&h, node); 46 | ++n; 47 | } 48 | } 49 | return n; 50 | } 51 | int test_str(int N, char * const *data) 52 | { 53 | strtree_t h; 54 | strnode_t d, *node; 55 | int i, n = 0; 56 | strtree_new(&h, 11); 57 | for (i = 0; i < N; ++i) { 58 | d.key = data[i]; 59 | node = strtree_search(&h, &d); 60 | if (node) { 61 | strtree_remove(&h, node); 62 | free(node); 63 | --n; 64 | } else { 65 | node = (strnode_t*)malloc(sizeof(strnode_t)); 66 | node->key = data[i]; node->val = i; 67 | strtree_insert(&h, node); 68 | ++n; 69 | } 70 | } 71 | return n; 72 | } 73 | 74 | int main(int argc, char *argv[]) 75 | { 76 | return udb_benchmark(argc, argv, test_int, test_str); 77 | } 78 | -------------------------------------------------------------------------------- /src/NP_rbtree/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "benchmark.h" 4 | #include "tree.h" 5 | 6 | typedef struct intnode_s intnode_t; 7 | struct intnode_s { 8 | RB_ENTRY(intnode_s) link; 9 | unsigned key; 10 | int val; 11 | }; 12 | typedef struct inttree_s inttree_t; 13 | RB_HEAD(inttree_s, intnode_s); 14 | static int int_cmp(intnode_t *a, intnode_t *b) { return (a->key > b->key) - (a->key < b->key); } 15 | RB_GENERATE_STATIC(inttree_s, intnode_s, link, int_cmp); 16 | 17 | typedef struct strnode_s strnode_t; 18 | struct strnode_s { 19 | RB_ENTRY(strnode_s) link; 20 | char *key; 21 | int val; 22 | }; 23 | typedef struct strtree_s strtree_t; 24 | RB_HEAD(strtree_s, strnode_s); 25 | static int str_cmp(strnode_t *a, strnode_t *b) { return strcmp(a->key, b->key); } 26 | RB_GENERATE_STATIC(strtree_s, strnode_s, link, str_cmp); 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | inttree_t h; 31 | intnode_t d, *node; 32 | int i, n = 0; 33 | RB_INIT(&h); 34 | for (i = 0; i < N; ++i) { 35 | d.key = data[i]; 36 | node = RB_FIND(inttree_s, &h, &d); 37 | if (node) { 38 | RB_REMOVE(inttree_s, &h, node); 39 | free(node); 40 | --n; 41 | } else { 42 | node = (intnode_t*)malloc(sizeof(intnode_t)); 43 | node->key = data[i]; node->val = i; 44 | RB_INSERT(inttree_s, &h, node); 45 | ++n; 46 | } 47 | } 48 | return n; 49 | } 50 | int test_str(int N, char * const *data) 51 | { 52 | strtree_t h; 53 | strnode_t d, *node; 54 | int i, n = 0; 55 | RB_INIT(&h); 56 | for (i = 0; i < N; ++i) { 57 | d.key = data[i]; 58 | node = RB_FIND(strtree_s, &h, &d); 59 | if (node) { 60 | RB_REMOVE(strtree_s, &h, node); 61 | free(node); 62 | --n; 63 | } else { 64 | node = (strnode_t*)malloc(sizeof(strnode_t)); 65 | node->key = data[i]; node->val = i; 66 | RB_INSERT(strtree_s, &h, node); 67 | ++n; 68 | } 69 | } 70 | return n; 71 | return 0; 72 | } 73 | 74 | int main(int argc, char *argv[]) 75 | { 76 | return udb_benchmark(argc, argv, test_int, test_str); 77 | } 78 | -------------------------------------------------------------------------------- /src/JE_trp_prng/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "benchmark.h" 7 | #include "trp.h" 8 | 9 | typedef struct intnode_s intnode_t; 10 | struct intnode_s { 11 | trp_node(intnode_t) link; 12 | unsigned key; 13 | int val; 14 | }; 15 | static int int_cmp(intnode_t *a, intnode_t *b) { return (a->key > b->key) - (a->key < b->key); } 16 | typedef trp(intnode_t) inttree_t; 17 | trp_gen(static, inttree_, inttree_t, intnode_t, link, int_cmp, 1297, 1301); 18 | 19 | typedef struct strnode_s strnode_t; 20 | struct strnode_s { 21 | trp_node(strnode_t) link; 22 | char *key; 23 | int val; 24 | }; 25 | typedef trp(strnode_t) strtree_t; 26 | static int str_cmp(strnode_t *a, strnode_t *b) { return strcmp(a->key, b->key); } 27 | trp_gen(static, strtree_, strtree_t, strnode_t, link, str_cmp, 1297, 1301); 28 | 29 | int test_int(int N, const unsigned *data) 30 | { 31 | inttree_t h; 32 | intnode_t d, *node; 33 | int i, n = 0; 34 | inttree_new(&h, 11); 35 | for (i = 0; i < N; ++i) { 36 | d.key = data[i]; 37 | node = inttree_search(&h, &d); 38 | if (node) { 39 | inttree_remove(&h, node); 40 | free(node); 41 | --n; 42 | } else { 43 | node = (intnode_t*)malloc(sizeof(intnode_t)); 44 | node->key = data[i]; node->val = i; 45 | inttree_insert(&h, node); 46 | ++n; 47 | } 48 | } 49 | return n; 50 | } 51 | int test_str(int N, char * const *data) 52 | { 53 | strtree_t h; 54 | strnode_t d, *node; 55 | int i, n = 0; 56 | strtree_new(&h, 11); 57 | for (i = 0; i < N; ++i) { 58 | d.key = data[i]; 59 | node = strtree_search(&h, &d); 60 | if (node) { 61 | strtree_remove(&h, node); 62 | free(node); 63 | --n; 64 | } else { 65 | node = (strnode_t*)malloc(sizeof(strnode_t)); 66 | node->key = data[i]; node->val = i; 67 | strtree_insert(&h, node); 68 | ++n; 69 | } 70 | } 71 | return n; 72 | } 73 | 74 | int main(int argc, char *argv[]) 75 | { 76 | return udb_benchmark(argc, argv, test_int, test_str); 77 | } 78 | -------------------------------------------------------------------------------- /src/htable/test.c.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "benchmark.h" 6 | #include "htable.h" 7 | 8 | #define HASH_SIZE 127 9 | 10 | struct myitem { 11 | int value; 12 | struct hash_entry entry; 13 | }; 14 | 15 | struct hash_table mytable; 16 | 17 | inline int comp(const void *i, const void *j, size_t len) 18 | { 19 | return *(int *)i - *(int *)j; 20 | } 21 | 22 | int test_int(int N, const unsigned *data) 23 | { 24 | struct hash_entry *hentry; 25 | struct myitem *tmp; 26 | unsigned int len; 27 | int i; 28 | 29 | hash_table_init(&mytable, HASH_SIZE, comp); 30 | for (i = 0; i < N; ++i) { 31 | len = sizeof(data[i]); 32 | if ((hentry = hash_table_lookup_key(&mytable, (char *)&data[i], len)) == NULL){ 33 | tmp = (struct myitem *)malloc(sizeof(struct myitem)); 34 | memset(tmp, 0, sizeof(struct myitem)); 35 | tmp->value = i; 36 | hash_table_insert(&mytable, &tmp->entry, (char *)&data[i], len); 37 | } else { 38 | hash_table_del_entry(&mytable, hentry); 39 | tmp = hash_entry(hentry, struct myitem, entry); 40 | hash_entry_finit(hentry); 41 | free(tmp); 42 | } 43 | } 44 | return mytable.num_elems; 45 | } 46 | 47 | int test_str(int N, char * const *data) 48 | { 49 | struct hash_entry *hentry; 50 | struct myitem *tmp; 51 | unsigned int len; 52 | int i; 53 | 54 | hash_table_init(&mytable, HASH_SIZE, NULL); 55 | for (i = 0; i < N; ++i) { 56 | len = strlen(data[i]); 57 | if ((hentry = hash_table_lookup_key(&mytable, data[i], len)) == NULL){ 58 | tmp = (struct myitem *)malloc(sizeof(struct myitem)); 59 | memset(tmp, 0, sizeof(struct myitem)); 60 | tmp->value = i; 61 | hash_table_insert(&mytable, &tmp->entry, data[i], len); 62 | } else { 63 | hash_table_del_entry(&mytable, hentry); 64 | tmp = hash_entry(hentry, struct myitem, entry); 65 | hash_entry_finit(hentry); 66 | free(tmp); 67 | } 68 | } 69 | return mytable.num_elems; 70 | } 71 | 72 | int main(int argc, char *argv[]) 73 | { 74 | return udb_benchmark(argc, argv, test_int, test_str); 75 | } 76 | -------------------------------------------------------------------------------- /src/htable/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "benchmark.h" 6 | #define inline 7 | #include "htable.h" 8 | 9 | #define HASH_SIZE 127 10 | 11 | struct myitem { 12 | int value; 13 | struct hash_entry entry; 14 | }; 15 | 16 | struct hash_table mytable; 17 | 18 | inline int comp(const void *i, const void *j, size_t len) 19 | { 20 | return *(int *)i - *(int *)j; 21 | } 22 | 23 | int test_int(int N, const unsigned *data) 24 | { 25 | struct hash_entry *hentry; 26 | struct myitem *tmp; 27 | unsigned int len; 28 | int i; 29 | 30 | hash_table_init(&mytable, HASH_SIZE, comp); 31 | for (i = 0; i < N; ++i) { 32 | len = sizeof(data[i]); 33 | if ((hentry = hash_table_lookup_key(&mytable, (char *)&data[i], len)) == NULL){ 34 | tmp = (struct myitem *)malloc(sizeof(struct myitem)); 35 | memset(tmp, 0, sizeof(struct myitem)); 36 | tmp->value = i; 37 | hash_table_insert(&mytable, &tmp->entry, (char *)&data[i], len); 38 | } else { 39 | hash_table_del_entry(&mytable, hentry); 40 | tmp = hash_entry(hentry, struct myitem, entry); 41 | hash_entry_finit(hentry); 42 | free(tmp); 43 | } 44 | } 45 | return mytable.num_elems; 46 | } 47 | 48 | int test_str(int N, char * const *data) 49 | { 50 | struct hash_entry *hentry; 51 | struct myitem *tmp; 52 | unsigned int len; 53 | int i; 54 | 55 | hash_table_init(&mytable, HASH_SIZE, NULL); 56 | for (i = 0; i < N; ++i) { 57 | len = strlen(data[i]); 58 | if ((hentry = hash_table_lookup_key(&mytable, data[i], len)) == NULL){ 59 | tmp = (struct myitem *)malloc(sizeof(struct myitem)); 60 | memset(tmp, 0, sizeof(struct myitem)); 61 | tmp->value = i; 62 | hash_table_insert(&mytable, &tmp->entry, data[i], len); 63 | } else { 64 | hash_table_del_entry(&mytable, hentry); 65 | tmp = hash_entry(hentry, struct myitem, entry); 66 | hash_entry_finit(hentry); 67 | free(tmp); 68 | } 69 | } 70 | return mytable.num_elems; 71 | } 72 | 73 | int main(int argc, char *argv[]) 74 | { 75 | return udb_benchmark(argc, argv, test_int, test_str); 76 | } 77 | -------------------------------------------------------------------------------- /src/JE_rb_old/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "benchmark.h" 5 | #include "rb.h" 6 | 7 | typedef struct intnode_s intnode_t; 8 | struct intnode_s { 9 | rb_node(intnode_t) link; 10 | unsigned key; 11 | int val; 12 | }; 13 | typedef rb_tree(intnode_t) inttree_t; 14 | static inline int int_cmp(intnode_t *a, intnode_t *b) { return (a->key > b->key) - (a->key < b->key); } 15 | 16 | typedef struct strnode_s strnode_t; 17 | struct strnode_s { 18 | rb_node(strnode_t) link; 19 | char *key; 20 | int val; 21 | }; 22 | typedef rb_tree(strnode_t) strtree_t; 23 | static inline int str_cmp(strnode_t *a, strnode_t *b) { return strcmp(a->key, b->key); } 24 | 25 | int test_int(int N, const unsigned *data) 26 | { 27 | inttree_t h; 28 | intnode_t d, *node; 29 | int i, n = 0; 30 | rb_tree_new(&h, link); 31 | for (i = 0; i < N; ++i) { 32 | rb_node_new(&h, &d, link); 33 | d.key = data[i]; 34 | rb_search(&h, &d, int_cmp, link, node); 35 | if (node != rb_tree_nil(&h)) { 36 | rb_remove(&h, node, intnode_t, link); 37 | free(node); 38 | --n; 39 | } else { 40 | node = (intnode_t*)malloc(sizeof(intnode_t)); 41 | rb_node_new(&h, node, link); 42 | node->key = data[i]; node->val = i; 43 | rb_insert(&h, node, int_cmp, intnode_t, link); 44 | ++n; 45 | } 46 | } 47 | return n; 48 | } 49 | int test_str(int N, char * const *data) 50 | { 51 | strtree_t h; 52 | strnode_t d, *node; 53 | int i, n = 0; 54 | rb_tree_new(&h, link); 55 | for (i = 0; i < N; ++i) { 56 | rb_node_new(&h, &d, link); 57 | d.key = data[i]; 58 | rb_search(&h, &d, str_cmp, link, node); 59 | if (node != rb_tree_nil(&h)) { 60 | rb_remove(&h, node, strnode_t, link); 61 | free(node); 62 | --n; 63 | } else { 64 | node = (strnode_t*)malloc(sizeof(strnode_t)); 65 | rb_node_new(&h, node, link); 66 | node->key = data[i]; node->val = i; 67 | rb_insert(&h, node, str_cmp, strnode_t, link); 68 | ++n; 69 | } 70 | } 71 | return n; 72 | } 73 | 74 | int main(int argc, char *argv[]) 75 | { 76 | return udb_benchmark(argc, argv, test_int, test_str); 77 | } 78 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/type_traits.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_TYPETRAITS_H 2 | #define RDESTL_TYPETRAITS_H 3 | 4 | namespace rde 5 | { 6 | 7 | template struct is_integral 8 | { 9 | enum { value = false }; 10 | }; 11 | 12 | template struct is_floating_point 13 | { 14 | enum { value = false }; 15 | }; 16 | 17 | #define RDE_INTEGRAL(TYPE) template<> struct is_integral { enum { value = true }; } 18 | 19 | RDE_INTEGRAL(char); 20 | RDE_INTEGRAL(bool); 21 | RDE_INTEGRAL(short); 22 | RDE_INTEGRAL(int); 23 | RDE_INTEGRAL(long); 24 | RDE_INTEGRAL(wchar_t); 25 | 26 | template<> struct is_floating_point { enum { value = true }; }; 27 | template<> struct is_floating_point { enum { value = true }; }; 28 | 29 | template struct is_pointer 30 | { 31 | enum { value = false }; 32 | }; 33 | template struct is_pointer 34 | { 35 | enum { value = true }; 36 | }; 37 | 38 | template struct is_pod 39 | { 40 | enum { value = false }; 41 | }; 42 | 43 | template struct is_fundamental 44 | { 45 | enum 46 | { 47 | value = is_integral::value || is_floating_point::value 48 | }; 49 | }; 50 | 51 | template struct has_trivial_constructor 52 | { 53 | enum 54 | { 55 | value = is_fundamental::value || is_pointer::value || is_pod::value 56 | }; 57 | }; 58 | 59 | template struct has_trivial_copy 60 | { 61 | enum 62 | { 63 | value = is_fundamental::value || is_pointer::value || is_pod::value 64 | }; 65 | }; 66 | 67 | template struct has_trivial_assign 68 | { 69 | enum 70 | { 71 | value = is_fundamental::value || is_pointer::value || is_pod::value 72 | }; 73 | }; 74 | 75 | template struct has_trivial_destructor 76 | { 77 | enum 78 | { 79 | value = is_fundamental::value || is_pointer::value || is_pod::value 80 | }; 81 | }; 82 | 83 | } // namespace rde 84 | 85 | //----------------------------------------------------------------------------- 86 | #endif // #ifndef RDESTL_TYPETRAITS_H 87 | 88 | -------------------------------------------------------------------------------- /src/JG_btree/btreepriv.h.ORG: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 1997-1999, 2001 John-Mark Gurney. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $Id: btreepriv.h,v 1.4.2.1 2001/03/28 06:17:12 jmg Exp $ 27 | * 28 | */ 29 | 30 | #ifndef _BTREEPRIV_H_ 31 | #define _BTREEPRIV_H_ 32 | 33 | #include 34 | 35 | struct btree { 36 | struct btreenode *root; 37 | bt_cmp_t cmp; 38 | int keyoff; 39 | int nodeptroff; 40 | int nkeys; 41 | int t; 42 | int nbits; 43 | int textra; 44 | #ifdef STATS 45 | int numkeys; 46 | int numnodes; 47 | #endif STATS 48 | }; 49 | 50 | struct btreenode { 51 | int leaf : 1; 52 | int n : 15; 53 | }; 54 | 55 | #define KEYS(btr, x) ((void **)((char *)x + btr->keyoff)) 56 | #define NODES(btr, x) ((struct btreenode **)((char *)x + btr->nodeptroff)) 57 | 58 | #endif /* _BTREEPRIV_H_ */ 59 | -------------------------------------------------------------------------------- /src/JG_btree/btreepriv.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 1997-1999, 2001 John-Mark Gurney. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $Id: btreepriv.h,v 1.4.2.1 2001/03/28 06:17:12 jmg Exp $ 27 | * 28 | */ 29 | 30 | #ifndef _BTREEPRIV_H_ 31 | #define _BTREEPRIV_H_ 32 | 33 | #include 34 | 35 | struct btree { 36 | struct btreenode *root; 37 | bt_cmp_t cmp; 38 | int keyoff; 39 | int nodeptroff; 40 | int nkeys; 41 | int t; 42 | int nbits; 43 | int textra; 44 | #ifdef STATS 45 | int numkeys; 46 | int numnodes; 47 | #endif /* STATS */ 48 | }; 49 | 50 | struct btreenode { 51 | int leaf : 1; 52 | int n : 15; 53 | }; 54 | 55 | #define KEYS(btr, x) ((void **)((char *)x + btr->keyoff)) 56 | #define NODES(btr, x) ((struct btreenode **)((char *)x + btr->nodeptroff)) 57 | 58 | #endif /* _BTREEPRIV_H_ */ 59 | -------------------------------------------------------------------------------- /src/NP_splaytree/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "benchmark.h" 4 | #include "tree.h" 5 | 6 | typedef struct intnode_s intnode_t; 7 | struct intnode_s { 8 | SPLAY_ENTRY(intnode_s) link; 9 | unsigned key; 10 | int val; 11 | }; 12 | typedef struct inttree_s inttree_t; 13 | SPLAY_HEAD(inttree_s, intnode_s); 14 | static int int_cmp(intnode_t *a, intnode_t *b) { return (a->key > b->key) - (a->key < b->key); } 15 | SPLAY_PROTOTYPE(inttree_s, intnode_s, link, int_cmp); 16 | SPLAY_GENERATE(inttree_s, intnode_s, link, int_cmp); 17 | 18 | typedef struct strnode_s strnode_t; 19 | struct strnode_s { 20 | SPLAY_ENTRY(strnode_s) link; 21 | char *key; 22 | int val; 23 | }; 24 | typedef struct strtree_s strtree_t; 25 | SPLAY_HEAD(strtree_s, strnode_s); 26 | static int str_cmp(strnode_t *a, strnode_t *b) { return strcmp(a->key, b->key); } 27 | SPLAY_PROTOTYPE(strtree_s, strnode_s, link, str_cmp); 28 | SPLAY_GENERATE(strtree_s, strnode_s, link, str_cmp); 29 | 30 | int test_int(int N, const unsigned *data) 31 | { 32 | inttree_t h; 33 | intnode_t d, *node; 34 | int i, n = 0; 35 | SPLAY_INIT(&h); 36 | for (i = 0; i < N; ++i) { 37 | d.key = data[i]; 38 | node = SPLAY_FIND(inttree_s, &h, &d); 39 | if (node) { 40 | SPLAY_REMOVE(inttree_s, &h, node); 41 | free(node); 42 | --n; 43 | } else { 44 | node = (intnode_t*)malloc(sizeof(intnode_t)); 45 | node->key = data[i]; node->val = i; 46 | SPLAY_INSERT(inttree_s, &h, node); 47 | ++n; 48 | } 49 | } 50 | return n; 51 | } 52 | int test_str(int N, char * const *data) 53 | { 54 | strtree_t h; 55 | strnode_t d, *node; 56 | int i, n = 0; 57 | SPLAY_INIT(&h); 58 | for (i = 0; i < N; ++i) { 59 | d.key = data[i]; 60 | node = SPLAY_FIND(strtree_s, &h, &d); 61 | if (node) { 62 | SPLAY_REMOVE(strtree_s, &h, node); 63 | free(node); 64 | --n; 65 | } else { 66 | node = (strnode_t*)malloc(sizeof(strnode_t)); 67 | node->key = data[i]; node->val = i; 68 | SPLAY_INSERT(strtree_s, &h, node); 69 | ++n; 70 | } 71 | } 72 | return n; 73 | return 0; 74 | } 75 | 76 | int main(int argc, char *argv[]) 77 | { 78 | return udb_benchmark(argc, argv, test_int, test_str); 79 | } 80 | -------------------------------------------------------------------------------- /src/JG_btree/btree.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright 1997, 1998, 2001 John-Mark Gurney. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $Id: btree.h,v 1.4.2.1 2001/03/28 06:17:12 jmg Exp $ 27 | * 28 | */ 29 | 30 | #ifndef _BTREE_H_ 31 | #define _BTREE_H_ 32 | 33 | struct btree; 34 | 35 | #define BT_SIZEDEF 128 36 | 37 | typedef void *bt_data_t; 38 | typedef int (*bt_cmp_t)(bt_data_t, bt_data_t); 39 | 40 | struct btree *bt_create(bt_cmp_t , int nodesize); 41 | void bt_insert(struct btree *, bt_data_t); 42 | void bt_dumptree(struct btree *); 43 | void bt_treestats(struct btree *); 44 | void *bt_delete(struct btree *, bt_data_t); 45 | int bt_checktree(struct btree *, bt_data_t min, bt_data_t max); 46 | void *bt_max(struct btree *); 47 | void *bt_min(struct btree *); 48 | void *bt_find(struct btree *, bt_data_t); 49 | 50 | #endif /* _BTREE_H_ */ 51 | -------------------------------------------------------------------------------- /src/sglib_rbtree/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "benchmark.h" 4 | 5 | typedef struct intmap_t { 6 | unsigned key; 7 | int value; 8 | char color; 9 | struct intmap_t *l, *r; 10 | } intmap_t; 11 | 12 | typedef struct strmap_t { 13 | char *key; 14 | int value; 15 | char color; 16 | struct strmap_t *l, *r; 17 | } strmap_t; 18 | 19 | #define __intcmp(a, b) (((a)->key > (b)->key) - ((a)->key < (b)->key)) 20 | #define __strcmp(a, b) strcmp((a)->key, (b)->key) 21 | 22 | #include "sglib.h" 23 | SGLIB_DEFINE_RBTREE_PROTOTYPES(intmap_t, l, r, color, __intcmp); 24 | SGLIB_DEFINE_RBTREE_FUNCTIONS(intmap_t, l, r, color, __intcmp); 25 | SGLIB_DEFINE_RBTREE_PROTOTYPES(strmap_t, l, r, color, __strcmp); 26 | SGLIB_DEFINE_RBTREE_FUNCTIONS(strmap_t, l, r, color, __strcmp); 27 | 28 | int test_int(int N, const unsigned *data) 29 | { 30 | int i, n = 0; 31 | intmap_t d, *h, *r; 32 | h = 0; 33 | for (i = 0; i < N; ++i) { 34 | d.key = data[i]; 35 | if ((r = sglib_intmap_t_find_member(h, &d)) == 0) { 36 | r = (intmap_t*)malloc(sizeof(intmap_t)); 37 | r->key = data[i]; r->value = i; 38 | sglib_intmap_t_add(&h, r); 39 | ++n; 40 | } else { 41 | sglib_intmap_t_delete(&h, r); 42 | free(r); 43 | --n; 44 | } 45 | } 46 | return n; 47 | } 48 | int test_int_alt(int N, const unsigned *data) // this is slower 49 | { 50 | int i, n = 0; 51 | intmap_t *h, *r, *t; 52 | h = 0; 53 | for (i = 0; i < N; ++i) { 54 | r = (intmap_t*)malloc(sizeof(intmap_t)); 55 | r->key = data[i]; r->value = i; 56 | if (!sglib_intmap_t_add_if_not_member(&h, r, &t)) { 57 | sglib_intmap_t_delete(&h, t); 58 | free(r); free(t); 59 | --n; 60 | } else ++n; 61 | } 62 | return n; 63 | } 64 | int test_str(int N, char * const *data) 65 | { 66 | int i, n = 0; 67 | strmap_t d, *h, *r; 68 | h = 0; 69 | for (i = 0; i < N; ++i) { 70 | d.key = data[i]; 71 | if ((r = sglib_strmap_t_find_member(h, &d)) == 0) { 72 | r = (strmap_t*)malloc(sizeof(strmap_t)); 73 | r->key = data[i]; r->value = i; 74 | sglib_strmap_t_add(&h, r); 75 | ++n; 76 | } else { 77 | sglib_strmap_t_delete(&h, r); 78 | free(r); 79 | --n; 80 | } 81 | } 82 | return n; 83 | } 84 | 85 | int main(int argc, char *argv[]) 86 | { 87 | return udb_benchmark(argc, argv, test_int, test_str); 88 | } 89 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_ITERATOR_H 2 | #define RDESTL_ITERATOR_H 3 | 4 | #include "rdestl/rdestl.h" 5 | 6 | namespace rde 7 | { 8 | 9 | //----------------------------------------------------------------------------- 10 | struct input_iterator_tag {}; 11 | struct output_iterator_tag {}; 12 | struct forward_iterator_tag: public input_iterator_tag {}; 13 | struct bidirectional_iterator_tag: public forward_iterator_tag {}; 14 | struct random_access_iterator_tag: public bidirectional_iterator_tag {}; 15 | 16 | //----------------------------------------------------------------------------- 17 | template 18 | struct iterator_traits 19 | { 20 | typedef typename IterT::iterator_category iterator_category; 21 | }; 22 | 23 | template 24 | struct iterator_traits 25 | { 26 | typedef random_access_iterator_tag iterator_category; 27 | }; 28 | 29 | //----------------------------------------------------------------------------- 30 | namespace internal 31 | { 32 | template RDE_FORCEINLINE 33 | void distance(TIter first, TIter last, TDist& dist, rde::random_access_iterator_tag) 34 | { 35 | dist = TDist(last - first); 36 | } 37 | template RDE_FORCEINLINE 38 | void distance(TIter first, TIter last, TDist& dist, rde::input_iterator_tag) 39 | { 40 | dist = 0; 41 | while (first != last) 42 | { 43 | ++dist; 44 | ++first; 45 | } 46 | } 47 | 48 | template RDE_FORCEINLINE 49 | void advance(TIter& iter, TDist d, rde::random_access_iterator_tag) 50 | { 51 | iter += d; 52 | } 53 | template RDE_FORCEINLINE 54 | void advance(TIter& iter, TDist d, rde::bidirectional_iterator_tag) 55 | { 56 | if (d >= 0) 57 | { 58 | while (d--) 59 | ++iter; 60 | } 61 | else 62 | { 63 | while (d++) 64 | --iter; 65 | } 66 | } 67 | template RDE_FORCEINLINE 68 | void advance(TIter& iter, TDist d, rde::input_iterator_tag) 69 | { 70 | RDE_ASSERT(d >= 0); 71 | while (d--) 72 | ++iter; 73 | } 74 | } // namespace internal 75 | } // namespace rde 76 | 77 | //----------------------------------------------------------------------------- 78 | #endif // #ifndef RDESTL_ITERATOR_H 79 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | # The list of directories to compile 2 | SUBDIRS = benchmark # library 3 | SUBDIRS += runit # test driver 4 | 5 | # C Macro implementations under test (header files included) 6 | SUBDIRS += khash 7 | SUBDIRS += kbtree 8 | SUBDIRS += htable 9 | SUBDIRS += stb_hash 10 | SUBDIRS += uthash 11 | SUBDIRS += sglib_rbtree 12 | SUBDIRS += NP_rbtree 13 | SUBDIRS += NP_splaytree 14 | SUBDIRS += JG_btree 15 | SUBDIRS += JE_rb_new 16 | SUBDIRS += JE_rb_old 17 | SUBDIRS += JE_trp_hash 18 | SUBDIRS += JE_trp_prng 19 | SUBDIRS += TN_rbtree 20 | 21 | # C implementations under test (library files included) 22 | SUBDIRS += libavl_avl 23 | SUBDIRS += libavl_rb 24 | SUBDIRS += libavl_prb 25 | SUBDIRS += libavl_bst 26 | 27 | # C implementations under test (require packages installed) 28 | SUBDIRS += _glib_hash 29 | SUBDIRS += _glib_tree 30 | # SUBDIRS += _gdsl_rb # only in my development environment 31 | 32 | # C++ implementations under test (library files included) 33 | SUBDIRS += rdestl 34 | SUBDIRS += tr1_unordered_map 35 | SUBDIRS += sgi_map 36 | SUBDIRS += sgi_hash_map 37 | SUBDIRS += stx_btree 38 | SUBDIRS += google_dense 39 | SUBDIRS += google_sparse 40 | SUBDIRS += libavl_avl_cpp 41 | SUBDIRS += libavl_rb_cpp 42 | SUBDIRS += libavl_rb_cpp2 43 | 44 | # C++ implementations under test (require packages installed) 45 | SUBDIRS += _boost_hash 46 | SUBDIRS += _qt_qhash 47 | SUBDIRS += _qt_qmap 48 | 49 | # failed 50 | # SUBDIRS += GM_avl 51 | # SUBDIRS += stlavlmap 52 | # SUBDIRS += WK_avl 53 | 54 | # The main target is responsible to compile all 55 | all: 56 | @for dir in ${SUBDIRS} ; do \ 57 | if [ -d $$dir ] ; then \ 58 | echo "Making sub-directory $$dir ..." ; \ 59 | (cd $$dir && make -s) ; \ 60 | fi \ 61 | done 62 | 63 | # Cleanup rules 64 | clean distclean: 65 | @rm -f *~ 66 | @for dir in ${SUBDIRS} ; do \ 67 | if [ -d $$dir ] ; then \ 68 | (cd $$dir && make -s clean) ; \ 69 | fi \ 70 | done 71 | 72 | # Run tests 73 | DRIVER = runit/runit 74 | PROGRAMS = $(shell ls -1 */test) 75 | TYPES = i s 76 | run: 77 | @for t in ${TYPES}; do \ 78 | for p in ${PROGRAMS} ; do \ 79 | if [ -x $$p ] ; then \ 80 | echo "Running test $$p (-$$t). Please wait ..." ; \ 81 | ${DRIVER} $$p -$$t ; \ 82 | fi \ 83 | done \ 84 | done 85 | -------------------------------------------------------------------------------- /src/README: -------------------------------------------------------------------------------- 1 | CPU: Xeon E5440 @ 2.83GHz (x64) 2 | OS: Debian GNU/Linux 5.0 3 | Kernel: 2.6.27 4 | Gcc: 4.3.2 5 | Option: -g -O2 -fomit-frame-pointer 6 | Design: 1) Generate a random array of 5 million integers with 1.25 million distict keys 7 | 2) For each integer, test if it exists in the dictionary; add if absent; delete if present 8 | 3) To test the performance given string keys, convert integers to strings with sprintf() 9 | 4) CPU time excludes time to generate the array 10 | 5) Memory excludes the memory allocated to the char* pointers 11 | 12 | Comments: The performance may be highly correlated with the size of data input due to rehashing. 13 | 14 | ===================================================================================================== 15 | Integer String 16 | Library Version CPU/sec Mem/MB CPU/sec Mem/MB Comment 17 | ----------------------------------------------------------------------------------------------------- 18 | glib-hash 2.22 2.26 44.4 2.60 49.2 C void ptr; chaining 19 | google_dense* 1.9 0.52 32.2 1.96 64.2 C++ template 20 | google_sparse* 1.9 1.58 8.9 4.62 14.9 C++ template 21 | hash_map gcc-4.3.2 1.38 25.1 2.40 25.1 C++ template; chaining 22 | khash* 0.2.6 0.56 17.4 1.90 25.6 C macro; double hashing 23 | stb-hash* 2.23 1.48 15.8 5.68 64.9 C macro 24 | unordered_map/gcc gcc-4.3.2 1.20 28.0 2.40 28.0 C++ template 25 | unordered_map/boost 1.45.0 1.36 25.2 2.42 25.2 C++ template 26 | uthash* 1.9.3 2.22 55.3 3.22 55.3 C macro 27 | ----------------------------------------------------------------------------------------------------- 28 | glib-tree 2.22 9.06 52.7 11.86 52.7 C void ptr; RB-tree 29 | kbtree* 20110116 2.46 8.8 10.56 16.8 C macro; B-tree 30 | map gcc-4.3.2 4.88 28.7 10.18 38.2 C++ template; RB-tree 31 | NP-rbtree* 20071228 5.12 28.2 10.38 37.7 C macro; RB-tree 32 | stx-btree* 0.8.3 1.94 9.0 9.88 14.3 C++ template; B+ tree 33 | ===================================================================================================== 34 | * Library source codes included. 35 | -------------------------------------------------------------------------------- /src/benchmark/benchmark.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "runlib.h" 7 | 8 | static int data_size = 5000000; 9 | static unsigned *int_data; 10 | static char **str_data; 11 | 12 | void udb_init_data() 13 | { 14 | int i; 15 | char buf[256]; 16 | printf("[benchmark] generating data... "); 17 | srand48(11); 18 | int_data = (unsigned*)calloc(data_size, sizeof(unsigned)); 19 | str_data = (char**)calloc(data_size, sizeof(char*)); 20 | for (i = 0; i < data_size; ++i) { 21 | int_data[i] = (unsigned)(data_size * drand48() / 4) * 271828183u; 22 | sprintf(buf, "%x", int_data[i]); 23 | str_data[i] = strdup(buf); 24 | } 25 | printf("done!\n"); 26 | } 27 | void udb_destroy_data() 28 | { 29 | int i; 30 | for (i = 0; i < data_size; ++i) free(str_data[i]); 31 | free(str_data); free(int_data); 32 | } 33 | static void udb_timing_int(int (*func)(int, const unsigned*)) 34 | { 35 | RunProcDyn rpd0, rpd1; 36 | double ut, st; 37 | int ret; 38 | pid_t pid = getpid(); 39 | run_get_dynamic_proc_info(pid, &rpd0); 40 | ret = func(data_size, int_data); 41 | run_get_dynamic_proc_info(pid, &rpd1); 42 | printf("[int data] # elements: %d\n", ret); 43 | ut = rpd1.utime - rpd0.utime; 44 | st = rpd1.stime - rpd0.stime; 45 | printf("[int data] CPU time: %.3lf (= %.3lf + %.3lf)\n", ut + st, ut, st); 46 | } 47 | static void udb_timing_str(int (*func)(int, char *const*)) 48 | { 49 | RunProcDyn rpd0, rpd1; 50 | double ut, st; 51 | int ret; 52 | pid_t pid = getpid(); 53 | run_get_dynamic_proc_info(pid, &rpd0); 54 | ret = func(data_size, str_data); 55 | run_get_dynamic_proc_info(pid, &rpd1); 56 | printf("[str data] # elements: %d\n", ret); 57 | ut = rpd1.utime - rpd0.utime; 58 | st = rpd1.stime - rpd0.stime; 59 | printf("[str data] CPU time: %.3lf (= %.3lf + %.3lf)\n", ut + st, ut, st); 60 | } 61 | int udb_benchmark(int argc, char *argv[], int (*func_int)(int, const unsigned*), int (*func_str)(int, char*const*)) 62 | { 63 | int c, flag = 0; 64 | size_t init_rss; 65 | RunProcDyn rpd; 66 | pid_t pid = getpid(); 67 | while ((c = getopt(argc, argv, "isn:")) >= 0) { 68 | switch (c) { 69 | case 'i': flag |= 1; break; 70 | case 's': flag |= 2; break; 71 | case 'n': data_size = atoi(optarg); break; 72 | } 73 | } 74 | if (flag == 0) { 75 | fprintf(stdout, "Usage: %s [-is] [-n %d]\n", argv[0], data_size); 76 | return 1; 77 | } 78 | udb_init_data(); 79 | run_get_dynamic_proc_info(pid, &rpd); 80 | init_rss = rpd.rss; 81 | printf("[benchmark] initial rss: %.3lf kB\n", rpd.rss/1024.0); 82 | if (flag & 1) udb_timing_int(func_int); 83 | if (flag & 2) udb_timing_str(func_str); 84 | run_get_dynamic_proc_info(pid, &rpd); 85 | printf("[benchmark] rss diff: %.3lf kB\n", (rpd.rss - init_rss) / 1024.0); 86 | udb_destroy_data(); 87 | printf("[benchmark] finished!\n\n"); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/benchmark/benchmark.c.ORG: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "runlib.h" 7 | 8 | static int data_size = 5000000; 9 | static unsigned *int_data; 10 | static char **str_data; 11 | 12 | void udb_init_data() 13 | { 14 | int i; 15 | char buf[256]; 16 | printf("[benchmark] generating data... "); 17 | srand48(11); 18 | int_data = (unsigned*)calloc(data_size, sizeof(unsigned)); 19 | str_data = (char**)calloc(data_size, sizeof(char*)); 20 | for (i = 0; i < data_size; ++i) { 21 | int_data[i] = (unsigned)(data_size * drand48() / 4) * 271828183u; 22 | sprintf(buf, "%x", int_data[i]); 23 | str_data[i] = strdup(buf); 24 | } 25 | printf("done!\n"); 26 | } 27 | void udb_destroy_data() 28 | { 29 | int i; 30 | for (i = 0; i < data_size; ++i) free(str_data[i]); 31 | free(str_data); free(int_data); 32 | } 33 | static void udb_timing_int(int (*func)(int, const unsigned*)) 34 | { 35 | RunProcDyn rpd0, rpd1; 36 | double ut, st; 37 | int ret; 38 | pid_t pid = getpid(); 39 | run_get_dynamic_proc_info(pid, &rpd0); 40 | ret = func(data_size, int_data); 41 | run_get_dynamic_proc_info(pid, &rpd1); 42 | printf("[int data] # elements: %d\n", ret); 43 | ut = rpd1.utime - rpd0.utime; 44 | st = rpd1.stime - rpd0.stime; 45 | printf("[int data] CPU time: %.3lf (= %.3lf + %.3lf)\n", ut + st, ut, st); 46 | } 47 | static void udb_timing_str(int (*func)(int, char *const*)) 48 | { 49 | RunProcDyn rpd0, rpd1; 50 | double ut, st; 51 | int ret; 52 | pid_t pid = getpid(); 53 | run_get_dynamic_proc_info(pid, &rpd0); 54 | ret = func(data_size, str_data); 55 | run_get_dynamic_proc_info(pid, &rpd1); 56 | printf("[str data] # elements: %d\n", ret); 57 | ut = rpd1.utime - rpd0.utime; 58 | st = rpd1.stime - rpd0.stime; 59 | printf("[str data] CPU time: %.3lf (= %.3lf + %.3lf)\n", ut + st, ut, st); 60 | } 61 | int udb_benchmark(int argc, char *argv[], int (*func_int)(int, const unsigned*), int (*func_str)(int, char*const*)) 62 | { 63 | int c, flag = 0; 64 | size_t init_rss; 65 | RunProcDyn rpd; 66 | pid_t pid = getpid(); 67 | while ((c = getopt(argc, argv, "isn:")) >= 0) { 68 | switch (c) { 69 | case 'i': flag |= 1; break; 70 | case 's': flag |= 2; break; 71 | case 'n': data_size = atoi(optarg); break; 72 | } 73 | } 74 | if (flag == 0) { 75 | fprintf(stderr, "Usage: %s [-is] [-n %d]\n", argv[0], data_size); 76 | return 1; 77 | } 78 | udb_init_data(); 79 | run_get_dynamic_proc_info(pid, &rpd); 80 | init_rss = rpd.rss; 81 | printf("[benchmark] initial rss: %.3lf kB\n", rpd.rss/1024.0); 82 | if (flag & 1) udb_timing_int(func_int); 83 | if (flag & 2) udb_timing_str(func_str); 84 | run_get_dynamic_proc_info(pid, &rpd); 85 | printf("[benchmark] rss diff: %.3lf kB\n", (rpd.rss - init_rss) / 1024.0); 86 | udb_destroy_data(); 87 | printf("[benchmark] finished!\n\n"); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kudb - Benchmark of Dictionary Structures by Heng Li 2 | 3 | # Results for the impatients 4 | 5 | Data sorted by CPU Time (unsigned keys, int values) 6 | 7 | Linux nuc 3.2.0-4-amd64 #1 SMP Debian 3.2.81-1 x86_64 GNU/Linux 8 | 9 | | Rank | Implementation | CPU (secs) | Memory (kB) | # | Notes | 10 | | ---- | ----------------- | ---------- | ----------- | ------- | --------- | 11 | | 1 | rdestl | 0.360 | 265.432 | 625792 | | 12 | | 2 | khash | 0.530 | 228.424 | 625792 | | 13 | | 3 | google_dense | 0.640 | 249.068 | 625792 | | 14 | | 4 | tr1_unordered_map | 1.020 | 244.628 | 625792 | | 15 | | 5 | stb_hash | 1.170 | 232.076 | 625792 | | 16 | | 6 | sgi_hash_map | 1.220 | 241.744 | 625792 | | 17 | | 7 | google_sparse | 1.300 | 225.140 | 625792 | | 18 | | 8 | htable | 1.390 | 297.124 | 625792 | | 19 | | 9 | qt_qhash | 1.390 | 245.592 | 625792 | ** | 20 | | 10 | glib_hash | 1.540 | 256.348 | 625792 | ** | 21 | | 11 | uthash | 1.570 | 273.184 | 625792 | | 22 | | 12 | boost_hash | 1.820 | 241.752 | 625792 | ** | 23 | | 13 | stx_btree | 2.130 | 225.128 | 625792 | | 24 | | 14 | kbtree | 2.490 | 224.228 | 625792 | | 25 | | 15 | sgi_map | 4.040 | 245.456 | 625792 | | 26 | | 16 | JE_rb_old | 4.260 | 244.820 | 625792 | | 27 | | 17 | NP_rbtree | 4.280 | 244.820 | 625792 | | 28 | | 18 | libavl_rb_cpp | 4.600 | 245.456 | 625792 | | 29 | | 19 | TN_rbtree | 4.700 | 245.456 | 625792 | | 30 | | 20 | libavl_rb_cpp2 | 4.760 | 235.688 | 625792 | | 31 | | 21 | libavl_avl_cpp | 4.960 | 245.456 | 625792 | | 32 | | 22 | JE_rb_new | 5.480 | 234.784 | 625792 | | 33 | | 23 | sglib_rbtree | 5.500 | 244.820 | 625792 | | 34 | | 24 | libavl_avl | 5.920 | 264.356 | 625792 | | 35 | | 25 | libavl_prb | 5.960 | 264.356 | 625792 | | 36 | | 26 | libavl_rb | 6.110 | 264.356 | 625792 | | 37 | | 27 | JG_btree | 6.370 | 256.172 | 625792 | | 38 | | 28 | JE_trp_hash | 6.580 | 234.784 | 625792 | | 39 | | 29 | JE_trp_prng | 6.890 | 244.556 | 625792 | | 40 | | 30 | NP_splaytree | 6.970 | 234.788 | 625792 | | 41 | | 31 | gdsl_rb | 7.290 | 264.356 | 625792 | ** | 42 | | 32 | glib_tree | 7.470 | 270.052 | 625792 | ** | 43 | | 33 | libavl_bst | 7.910 | 254.588 | 625792 | | 44 | | 34 | qt_qmap | 8.420 | 237.624 | 625792 | ** | 45 | 46 | ** Pre-installation of System Libraries is required 47 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/set.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_SET_H 2 | #define RDESTL_SET_H 3 | 4 | #include "rdestl/rb_tree.h" 5 | #include "rdestl/iterator.h" 6 | 7 | namespace rde 8 | { 9 | template 11 | class set : private rb_tree 12 | { 13 | typedef rb_tree Base; 14 | 15 | template 16 | class node_iterator 17 | { 18 | public: 19 | typedef forward_iterator_tag iterator_category; 20 | 21 | explicit node_iterator(TNodePtr node, set* set_) 22 | : m_node(node), 23 | m_set(set_) 24 | {/**/} 25 | template 26 | node_iterator(const node_iterator& rhs) 27 | : m_node(rhs.node()), 28 | m_set(rhs.get_set()) 29 | { 30 | /**/ 31 | } 32 | 33 | TRef operator*() const 34 | { 35 | RDE_ASSERT(m_node != 0); 36 | return m_node->key; 37 | } 38 | TPtr operator->() const 39 | { 40 | return &m_node->key; 41 | } 42 | TNodePtr node() const 43 | { 44 | return m_node; 45 | } 46 | 47 | node_iterator& operator++() 48 | { 49 | RDE_ASSERT(m_node != 0); 50 | TNodePtr next = m_node->next; 51 | if (next == 0) 52 | next = find_next_node(m_node); 53 | m_node = next; 54 | return *this; 55 | } 56 | node_iterator operator++(int) 57 | { 58 | node_iterator copy(*this); 59 | ++(*this); 60 | return copy; 61 | } 62 | 63 | bool operator==(const node_iterator& rhs) const 64 | { 65 | return rhs.m_node == m_node && m_set == rhs.m_set; 66 | } 67 | bool operator!=(const node_iterator& rhs) const 68 | { 69 | return !(rhs == *this); 70 | } 71 | 72 | set* get_set() const { return m_set; } 73 | private: 74 | TNodePtr find_next_node(TNodePtr node) const 75 | { 76 | return 0; 77 | } 78 | 79 | TNodePtr m_node; 80 | set* m_set; 81 | }; 82 | 83 | public: 84 | typedef T value_type; 85 | typedef node_iterator iterator; 86 | typedef node_iterator const_iterator; 87 | typedef TAllocator allocator_type; 88 | 89 | explicit set(const allocator_type& allocator = allocator_type()) 90 | : rb_tree(allocator) {} 91 | 92 | iterator begin() 93 | { 94 | return iterator(Base::get_begin_node(), this); 95 | } 96 | const_iterator begin() const 97 | { 98 | return const_iterator(Base::get_begin_node(), this); 99 | } 100 | iterator end() 101 | { 102 | return iterator(0, this); 103 | } 104 | const_iterator end() const 105 | { 106 | return iterator(0, this); 107 | } 108 | 109 | iterator find(const value_type& v) 110 | { 111 | return iterator(Base::find_node(v), this); 112 | } 113 | const_iterator find(const value_type& v) const 114 | { 115 | return const_iterator(Base::find_node(v), this); 116 | } 117 | void erase(const value_type& v) 118 | { 119 | erase(find(v)); 120 | } 121 | void erase(iterator it) 122 | { 123 | RDE_ASSERT(it != end()); 124 | Base::erase(it.node()); 125 | } 126 | 127 | using Base::insert; 128 | using Base::empty; 129 | using Base::size; 130 | }; 131 | 132 | } // rde 133 | 134 | #endif // 135 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/simple_string_storage.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_SIMPLE_STRING_STORAGE_H 2 | #define RDESTL_SIMPLE_STRING_STORAGE_H 3 | 4 | namespace rde 5 | { 6 | template 7 | class simple_string_storage 8 | { 9 | public: 10 | typedef E value_type; 11 | typedef int size_type; 12 | typedef TAllocator allocator_type; 13 | typedef const value_type* const_iterator; 14 | static const unsigned long kGranularity = 32; 15 | 16 | explicit simple_string_storage(const allocator_type& allocator) 17 | : m_allocator(allocator), 18 | m_length(0) 19 | { 20 | m_data = construct_string(0); 21 | } 22 | simple_string_storage(const value_type* str, const allocator_type& allocator) 23 | : m_allocator(allocator) 24 | { 25 | const int len = strlen(str); 26 | m_data = construct_string(len); 27 | Sys::MemCpy(m_data, str, len*sizeof(value_type)); 28 | m_length = len; 29 | m_data[len] = 0; 30 | } 31 | simple_string_storage(const value_type* str, size_type len, 32 | const allocator_type& allocator) 33 | : m_allocator(allocator) 34 | { 35 | m_data = construct_string(len); 36 | Sys::MemCpy(m_data, str, len*sizeof(value_type)); 37 | m_length = len; 38 | m_data[len] = 0; 39 | } 40 | simple_string_storage(const simple_string_storage& rhs, const allocator_type& allocator) 41 | : m_allocator(allocator), 42 | m_capacity(0) 43 | { 44 | *this = rhs; 45 | } 46 | ~simple_string_storage() 47 | { 48 | release_string(); 49 | } 50 | 51 | // @note: doesnt copy allocator 52 | simple_string_storage& operator=(const simple_string_storage& rhs) 53 | { 54 | if (m_data != rhs.c_str()) 55 | { 56 | assign(rhs.c_str(), rhs.length()); 57 | } 58 | return *this; 59 | } 60 | 61 | void assign(const value_type* str, size_type len) 62 | { 63 | // Do not use with str = str.c_str()! 64 | RDE_ASSERT(str != m_data); 65 | if (m_capacity <= len + 1) 66 | { 67 | release_string(); 68 | m_data = construct_string(len); 69 | } 70 | Sys::MemCpy(m_data, str, len*sizeof(value_type)); 71 | m_length = len; 72 | m_data[len] = 0; 73 | } 74 | 75 | void append(const value_type* str, size_type len) 76 | { 77 | const size_type prevLen = length(); 78 | const size_type newLen = prevLen + len; 79 | if (m_capacity <= newLen + 1) 80 | { 81 | value_type* newData = construct_string(newLen); 82 | Sys::MemCpy(newData, m_data, prevLen * sizeof(value_type)); 83 | release_string(); 84 | m_data = newData; 85 | } 86 | Sys::MemCpy(m_data + prevLen, str, len * sizeof(value_type)); 87 | m_data[newLen] = 0; 88 | m_length = newLen; 89 | RDE_ASSERT(invariant()); 90 | } 91 | 92 | inline const value_type* c_str() const 93 | { 94 | return m_data; 95 | } 96 | inline size_type length() const 97 | { 98 | return m_length; 99 | } 100 | const allocator_type& get_allocator() const { return m_allocator; } 101 | 102 | void make_unique(size_type) {} 103 | value_type* get_data() { return m_data; } 104 | 105 | protected: 106 | bool invariant() const 107 | { 108 | RDE_ASSERT(m_data); 109 | RDE_ASSERT(m_length <= m_capacity); 110 | if (length() != 0) 111 | RDE_ASSERT(m_data[length()] == 0); 112 | return true; 113 | } 114 | private: 115 | value_type* construct_string(size_type capacity) 116 | { 117 | value_type* data(0); 118 | if (capacity != 0) 119 | { 120 | capacity = (capacity+kGranularity-1) & ~(kGranularity-1); 121 | if (capacity < kGranularity) 122 | capacity = kGranularity; 123 | 124 | const size_type toAlloc = sizeof(value_type)*(capacity + 1); 125 | void* mem = m_allocator.allocate(toAlloc); 126 | data = static_cast(mem); 127 | } 128 | else // empty string, no allocation needed. Use our internal buffer. 129 | { 130 | data = &m_end_of_data; 131 | } 132 | m_capacity = capacity; 133 | *data = 0; 134 | return data; 135 | } 136 | void release_string() 137 | { 138 | if (m_capacity != 0) 139 | { 140 | RDE_ASSERT(m_data != &m_end_of_data); 141 | m_allocator.deallocate(m_data, m_capacity); 142 | } 143 | } 144 | 145 | E* m_data; 146 | E m_end_of_data; 147 | size_type m_capacity; 148 | size_type m_length; 149 | TAllocator m_allocator; 150 | }; 151 | 152 | } // rde 153 | 154 | #endif // #ifndef RDESTL_SIMPLE_STRING_STORAGE_H 155 | -------------------------------------------------------------------------------- /src/libavl_prb/prb.h: -------------------------------------------------------------------------------- 1 | /* Produced by texiweb from libavl.w. */ 2 | 3 | /* libavl - library for manipulation of binary trees. 4 | Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | 02111-1307, USA. 20 | 21 | The author may be contacted at on the Internet, or 22 | write to Ben Pfaff, Stanford University, Computer Science Dept., 353 23 | Serra Mall, Stanford CA 94305, USA. 24 | */ 25 | 26 | #ifndef PRB_H 27 | #define PRB_H 1 28 | 29 | #include 30 | 31 | /* Function types. */ 32 | typedef int prb_comparison_func (const void *prb_a, const void *prb_b, 33 | void *prb_param); 34 | typedef void prb_item_func (void *prb_item, void *prb_param); 35 | typedef void *prb_copy_func (void *prb_item, void *prb_param); 36 | 37 | #ifndef LIBAVL_ALLOCATOR 38 | #define LIBAVL_ALLOCATOR 39 | /* Memory allocator. */ 40 | struct libavl_allocator 41 | { 42 | void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size); 43 | void (*libavl_free) (struct libavl_allocator *, void *libavl_block); 44 | }; 45 | #endif 46 | 47 | /* Default memory allocator. */ 48 | extern struct libavl_allocator prb_allocator_default; 49 | void *prb_malloc (struct libavl_allocator *, size_t); 50 | void prb_free (struct libavl_allocator *, void *); 51 | 52 | /* Maximum PRB height. */ 53 | #ifndef PRB_MAX_HEIGHT 54 | #define PRB_MAX_HEIGHT 48 55 | #endif 56 | 57 | /* Tree data structure. */ 58 | struct prb_table 59 | { 60 | struct prb_node *prb_root; /* Tree's root. */ 61 | prb_comparison_func *prb_compare; /* Comparison function. */ 62 | void *prb_param; /* Extra argument to |prb_compare|. */ 63 | struct libavl_allocator *prb_alloc; /* Memory allocator. */ 64 | size_t prb_count; /* Number of items in tree. */ 65 | }; 66 | 67 | /* Color of a red-black node. */ 68 | enum prb_color 69 | { 70 | PRB_BLACK, /* Black. */ 71 | PRB_RED /* Red. */ 72 | }; 73 | 74 | /* A red-black tree with parent pointers node. */ 75 | struct prb_node 76 | { 77 | struct prb_node *prb_link[2]; /* Subtrees. */ 78 | struct prb_node *prb_parent; /* Parent. */ 79 | void *prb_data; /* Pointer to data. */ 80 | unsigned char prb_color; /* Color. */ 81 | }; 82 | 83 | /* PRB traverser structure. */ 84 | struct prb_traverser 85 | { 86 | struct prb_table *prb_table; /* Tree being traversed. */ 87 | struct prb_node *prb_node; /* Current node in tree. */ 88 | }; 89 | 90 | /* Table functions. */ 91 | struct prb_table *prb_create (prb_comparison_func *, void *, 92 | struct libavl_allocator *); 93 | struct prb_table *prb_copy (const struct prb_table *, prb_copy_func *, 94 | prb_item_func *, struct libavl_allocator *); 95 | void prb_destroy (struct prb_table *, prb_item_func *); 96 | void **prb_probe (struct prb_table *, void *); 97 | void *prb_insert (struct prb_table *, void *); 98 | void *prb_replace (struct prb_table *, void *); 99 | void *prb_delete (struct prb_table *, const void *); 100 | void *prb_find (const struct prb_table *, const void *); 101 | void prb_assert_insert (struct prb_table *, void *); 102 | void *prb_assert_delete (struct prb_table *, void *); 103 | 104 | #define prb_count(table) ((size_t) (table)->prb_count) 105 | 106 | /* Table traverser functions. */ 107 | void prb_t_init (struct prb_traverser *, struct prb_table *); 108 | void *prb_t_first (struct prb_traverser *, struct prb_table *); 109 | void *prb_t_last (struct prb_traverser *, struct prb_table *); 110 | void *prb_t_find (struct prb_traverser *, struct prb_table *, void *); 111 | void *prb_t_insert (struct prb_traverser *, struct prb_table *, void *); 112 | void *prb_t_copy (struct prb_traverser *, const struct prb_traverser *); 113 | void *prb_t_next (struct prb_traverser *); 114 | void *prb_t_prev (struct prb_traverser *); 115 | void *prb_t_cur (struct prb_traverser *); 116 | void *prb_t_replace (struct prb_traverser *, void *); 117 | 118 | #endif /* prb.h */ 119 | -------------------------------------------------------------------------------- /src/libavl_avl/avl.h: -------------------------------------------------------------------------------- 1 | /* Produced by texiweb from libavl.w. */ 2 | 3 | /* libavl - library for manipulation of binary trees. 4 | Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | 02111-1307, USA. 20 | 21 | The author may be contacted at on the Internet, or 22 | write to Ben Pfaff, Stanford University, Computer Science Dept., 353 23 | Serra Mall, Stanford CA 94305, USA. 24 | */ 25 | 26 | #ifndef AVL_H 27 | #define AVL_H 1 28 | 29 | #include 30 | 31 | /* Function types. */ 32 | typedef int avl_comparison_func (const void *avl_a, const void *avl_b, 33 | void *avl_param); 34 | typedef void avl_item_func (void *avl_item, void *avl_param); 35 | typedef void *avl_copy_func (void *avl_item, void *avl_param); 36 | 37 | #ifndef LIBAVL_ALLOCATOR 38 | #define LIBAVL_ALLOCATOR 39 | /* Memory allocator. */ 40 | struct libavl_allocator 41 | { 42 | void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size); 43 | void (*libavl_free) (struct libavl_allocator *, void *libavl_block); 44 | }; 45 | #endif 46 | 47 | /* Default memory allocator. */ 48 | extern struct libavl_allocator avl_allocator_default; 49 | void *avl_malloc (struct libavl_allocator *, size_t); 50 | void avl_free (struct libavl_allocator *, void *); 51 | 52 | /* Maximum AVL height. */ 53 | #ifndef AVL_MAX_HEIGHT 54 | #define AVL_MAX_HEIGHT 32 55 | #endif 56 | 57 | /* Tree data structure. */ 58 | struct avl_table 59 | { 60 | struct avl_node *avl_root; /* Tree's root. */ 61 | avl_comparison_func *avl_compare; /* Comparison function. */ 62 | void *avl_param; /* Extra argument to |avl_compare|. */ 63 | struct libavl_allocator *avl_alloc; /* Memory allocator. */ 64 | size_t avl_count; /* Number of items in tree. */ 65 | unsigned long avl_generation; /* Generation number. */ 66 | }; 67 | 68 | /* An AVL tree node. */ 69 | struct avl_node 70 | { 71 | struct avl_node *avl_link[2]; /* Subtrees. */ 72 | void *avl_data; /* Pointer to data. */ 73 | signed char avl_balance; /* Balance factor. */ 74 | }; 75 | 76 | /* AVL traverser structure. */ 77 | struct avl_traverser 78 | { 79 | struct avl_table *avl_table; /* Tree being traversed. */ 80 | struct avl_node *avl_node; /* Current node in tree. */ 81 | struct avl_node *avl_stack[AVL_MAX_HEIGHT]; 82 | /* All the nodes above |avl_node|. */ 83 | size_t avl_height; /* Number of nodes in |avl_parent|. */ 84 | unsigned long avl_generation; /* Generation number. */ 85 | }; 86 | 87 | /* Table functions. */ 88 | struct avl_table *avl_create (avl_comparison_func *, void *, 89 | struct libavl_allocator *); 90 | struct avl_table *avl_copy (const struct avl_table *, avl_copy_func *, 91 | avl_item_func *, struct libavl_allocator *); 92 | void avl_destroy (struct avl_table *, avl_item_func *); 93 | void **avl_probe (struct avl_table *, void *); 94 | void *avl_insert (struct avl_table *, void *); 95 | void *avl_replace (struct avl_table *, void *); 96 | void *avl_delete (struct avl_table *, const void *); 97 | void *avl_find (const struct avl_table *, const void *); 98 | void avl_assert_insert (struct avl_table *, void *); 99 | void *avl_assert_delete (struct avl_table *, void *); 100 | 101 | #define avl_count(table) ((size_t) (table)->avl_count) 102 | 103 | /* Table traverser functions. */ 104 | void avl_t_init (struct avl_traverser *, struct avl_table *); 105 | void *avl_t_first (struct avl_traverser *, struct avl_table *); 106 | void *avl_t_last (struct avl_traverser *, struct avl_table *); 107 | void *avl_t_find (struct avl_traverser *, struct avl_table *, void *); 108 | void *avl_t_insert (struct avl_traverser *, struct avl_table *, void *); 109 | void *avl_t_copy (struct avl_traverser *, const struct avl_traverser *); 110 | void *avl_t_next (struct avl_traverser *); 111 | void *avl_t_prev (struct avl_traverser *); 112 | void *avl_t_cur (struct avl_traverser *); 113 | void *avl_t_replace (struct avl_traverser *, void *); 114 | 115 | #endif /* avl.h */ 116 | -------------------------------------------------------------------------------- /src/libavl_rb/rb.h: -------------------------------------------------------------------------------- 1 | /* Produced by texiweb from libavl.w. */ 2 | 3 | /* libavl - library for manipulation of binary trees. 4 | Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | 02111-1307, USA. 20 | 21 | The author may be contacted at on the Internet, or 22 | write to Ben Pfaff, Stanford University, Computer Science Dept., 353 23 | Serra Mall, Stanford CA 94305, USA. 24 | */ 25 | 26 | #ifndef RB_H 27 | #define RB_H 1 28 | 29 | #include 30 | 31 | /* Function types. */ 32 | typedef int rb_comparison_func (const void *rb_a, const void *rb_b, 33 | void *rb_param); 34 | typedef void rb_item_func (void *rb_item, void *rb_param); 35 | typedef void *rb_copy_func (void *rb_item, void *rb_param); 36 | 37 | #ifndef LIBAVL_ALLOCATOR 38 | #define LIBAVL_ALLOCATOR 39 | /* Memory allocator. */ 40 | struct libavl_allocator 41 | { 42 | void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size); 43 | void (*libavl_free) (struct libavl_allocator *, void *libavl_block); 44 | }; 45 | #endif 46 | 47 | /* Default memory allocator. */ 48 | extern struct libavl_allocator rb_allocator_default; 49 | void *rb_malloc (struct libavl_allocator *, size_t); 50 | void rb_free (struct libavl_allocator *, void *); 51 | 52 | /* Maximum RB height. */ 53 | #ifndef RB_MAX_HEIGHT 54 | #define RB_MAX_HEIGHT 48 55 | #endif 56 | 57 | /* Tree data structure. */ 58 | struct rb_table 59 | { 60 | struct rb_node *rb_root; /* Tree's root. */ 61 | rb_comparison_func *rb_compare; /* Comparison function. */ 62 | void *rb_param; /* Extra argument to |rb_compare|. */ 63 | struct libavl_allocator *rb_alloc; /* Memory allocator. */ 64 | size_t rb_count; /* Number of items in tree. */ 65 | unsigned long rb_generation; /* Generation number. */ 66 | }; 67 | 68 | /* Color of a red-black node. */ 69 | enum rb_color 70 | { 71 | RB_BLACK, /* Black. */ 72 | RB_RED /* Red. */ 73 | }; 74 | 75 | /* A red-black tree node. */ 76 | struct rb_node 77 | { 78 | struct rb_node *rb_link[2]; /* Subtrees. */ 79 | void *rb_data; /* Pointer to data. */ 80 | unsigned char rb_color; /* Color. */ 81 | }; 82 | 83 | /* RB traverser structure. */ 84 | struct rb_traverser 85 | { 86 | struct rb_table *rb_table; /* Tree being traversed. */ 87 | struct rb_node *rb_node; /* Current node in tree. */ 88 | struct rb_node *rb_stack[RB_MAX_HEIGHT]; 89 | /* All the nodes above |rb_node|. */ 90 | size_t rb_height; /* Number of nodes in |rb_parent|. */ 91 | unsigned long rb_generation; /* Generation number. */ 92 | }; 93 | 94 | /* Table functions. */ 95 | struct rb_table *rb_create (rb_comparison_func *, void *, 96 | struct libavl_allocator *); 97 | struct rb_table *rb_copy (const struct rb_table *, rb_copy_func *, 98 | rb_item_func *, struct libavl_allocator *); 99 | void rb_destroy (struct rb_table *, rb_item_func *); 100 | void **rb_probe (struct rb_table *, void *); 101 | void *rb_insert (struct rb_table *, void *); 102 | void *rb_replace (struct rb_table *, void *); 103 | void *rb_delete (struct rb_table *, const void *); 104 | void *rb_find (const struct rb_table *, const void *); 105 | void rb_assert_insert (struct rb_table *, void *); 106 | void *rb_assert_delete (struct rb_table *, void *); 107 | 108 | #define rb_count(table) ((size_t) (table)->rb_count) 109 | 110 | /* Table traverser functions. */ 111 | void rb_t_init (struct rb_traverser *, struct rb_table *); 112 | void *rb_t_first (struct rb_traverser *, struct rb_table *); 113 | void *rb_t_last (struct rb_traverser *, struct rb_table *); 114 | void *rb_t_find (struct rb_traverser *, struct rb_table *, void *); 115 | void *rb_t_insert (struct rb_traverser *, struct rb_table *, void *); 116 | void *rb_t_copy (struct rb_traverser *, const struct rb_traverser *); 117 | void *rb_t_next (struct rb_traverser *); 118 | void *rb_t_prev (struct rb_traverser *); 119 | void *rb_t_cur (struct rb_traverser *); 120 | void *rb_t_replace (struct rb_traverser *, void *); 121 | 122 | #endif /* rb.h */ 123 | -------------------------------------------------------------------------------- /src/libavl_bst/bst.h: -------------------------------------------------------------------------------- 1 | /* Produced by texiweb from libavl.w. */ 2 | 3 | /* libavl - library for manipulation of binary trees. 4 | Copyright (C) 1998-2002, 2004 Free Software Foundation, Inc. 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | 02111-1307, USA. 20 | 21 | The author may be contacted at on the Internet, or 22 | write to Ben Pfaff, Stanford University, Computer Science Dept., 353 23 | Serra Mall, Stanford CA 94305, USA. 24 | */ 25 | 26 | #ifndef BST_H 27 | #define BST_H 1 28 | 29 | #include 30 | 31 | /* Function types. */ 32 | typedef int bst_comparison_func (const void *bst_a, const void *bst_b, 33 | void *bst_param); 34 | typedef void bst_item_func (void *bst_item, void *bst_param); 35 | typedef void *bst_copy_func (void *bst_item, void *bst_param); 36 | 37 | #ifndef LIBAVL_ALLOCATOR 38 | #define LIBAVL_ALLOCATOR 39 | /* Memory allocator. */ 40 | struct libavl_allocator 41 | { 42 | void *(*libavl_malloc) (struct libavl_allocator *, size_t libavl_size); 43 | void (*libavl_free) (struct libavl_allocator *, void *libavl_block); 44 | }; 45 | #endif 46 | 47 | /* Default memory allocator. */ 48 | extern struct libavl_allocator bst_allocator_default; 49 | void *bst_malloc (struct libavl_allocator *, size_t); 50 | void bst_free (struct libavl_allocator *, void *); 51 | 52 | /* Maximum BST height. */ 53 | #ifndef BST_MAX_HEIGHT 54 | #define BST_MAX_HEIGHT 32 55 | #endif 56 | 57 | /* Tree data structure. */ 58 | struct bst_table 59 | { 60 | struct bst_node *bst_root; /* Tree's root. */ 61 | bst_comparison_func *bst_compare; /* Comparison function. */ 62 | void *bst_param; /* Extra argument to |bst_compare|. */ 63 | struct libavl_allocator *bst_alloc; /* Memory allocator. */ 64 | size_t bst_count; /* Number of items in tree. */ 65 | unsigned long bst_generation; /* Generation number. */ 66 | }; 67 | 68 | /* A binary search tree node. */ 69 | struct bst_node 70 | { 71 | struct bst_node *bst_link[2]; /* Subtrees. */ 72 | void *bst_data; /* Pointer to data. */ 73 | }; 74 | 75 | /* BST traverser structure. */ 76 | struct bst_traverser 77 | { 78 | struct bst_table *bst_table; /* Tree being traversed. */ 79 | struct bst_node *bst_node; /* Current node in tree. */ 80 | struct bst_node *bst_stack[BST_MAX_HEIGHT]; 81 | /* All the nodes above |bst_node|. */ 82 | size_t bst_height; /* Number of nodes in |bst_parent|. */ 83 | unsigned long bst_generation; /* Generation number. */ 84 | }; 85 | 86 | /* Table functions. */ 87 | struct bst_table *bst_create (bst_comparison_func *, void *, 88 | struct libavl_allocator *); 89 | struct bst_table *bst_copy (const struct bst_table *, bst_copy_func *, 90 | bst_item_func *, struct libavl_allocator *); 91 | void bst_destroy (struct bst_table *, bst_item_func *); 92 | void **bst_probe (struct bst_table *, void *); 93 | void *bst_insert (struct bst_table *, void *); 94 | void *bst_replace (struct bst_table *, void *); 95 | void *bst_delete (struct bst_table *, const void *); 96 | void *bst_find (const struct bst_table *, const void *); 97 | void bst_assert_insert (struct bst_table *, void *); 98 | void *bst_assert_delete (struct bst_table *, void *); 99 | 100 | #define bst_count(table) ((size_t) (table)->bst_count) 101 | 102 | /* Table traverser functions. */ 103 | void bst_t_init (struct bst_traverser *, struct bst_table *); 104 | void *bst_t_first (struct bst_traverser *, struct bst_table *); 105 | void *bst_t_last (struct bst_traverser *, struct bst_table *); 106 | void *bst_t_find (struct bst_traverser *, struct bst_table *, void *); 107 | void *bst_t_insert (struct bst_traverser *, struct bst_table *, void *); 108 | void *bst_t_copy (struct bst_traverser *, const struct bst_traverser *); 109 | void *bst_t_next (struct bst_traverser *); 110 | void *bst_t_prev (struct bst_traverser *); 111 | void *bst_t_cur (struct bst_traverser *); 112 | void *bst_t_replace (struct bst_traverser *, void *); 113 | 114 | /* Special BST functions. */ 115 | void bst_balance (struct bst_table *tree); 116 | 117 | #endif /* bst.h */ 118 | 119 | /* Table assertion functions. */ 120 | #ifndef NDEBUG 121 | #undef bst_assert_insert 122 | #undef bst_assert_delete 123 | #else 124 | #define bst_assert_insert(table, item) bst_insert (table, item) 125 | #define bst_assert_delete(table, item) bst_delete (table, item) 126 | #endif 127 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/sorted_vector.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_SORTED_VECTOR_H 2 | #define RDESTL_SORTED_VECTOR_H 3 | 4 | #include "rdestl/functional.h" 5 | #include "rdestl/pair.h" 6 | #include "rdestl/vector.h" 7 | 8 | namespace rde 9 | { 10 | namespace internal 11 | { 12 | //========================================================================= 13 | template 14 | struct compare_func 15 | { 16 | bool operator()(const TPair& lhs, const TPair& rhs) const 17 | { 18 | return TFunctor()(lhs.first, rhs.first); 19 | } 20 | bool operator()(const TPair& lhs, const typename TPair::first_type& rhs) const 21 | { 22 | return TFunctor()(lhs.first, rhs); 23 | } 24 | bool operator()(const typename TPair::first_type& lhs, const TPair& rhs) const 25 | { 26 | return TFunctor()(lhs, rhs.first); 27 | } 28 | }; 29 | } 30 | 31 | //============================================================================= 32 | template, 33 | class TAllocator = rde::allocator, 34 | class TStorage = rde::standard_vector_storage, TAllocator> > 35 | class sorted_vector : private vector, TAllocator, TStorage > 36 | { 37 | typedef vector, TAllocator, TStorage> Base; 38 | 39 | public: 40 | typedef TKey key_type; 41 | typedef TValue mapped_type; 42 | typedef typename Base::size_type size_type; 43 | typedef typename Base::value_type value_type; 44 | typedef typename Base::iterator iterator; 45 | typedef typename Base::const_iterator const_iterator; 46 | typedef typename Base::allocator_type allocator_type; 47 | 48 | explicit sorted_vector(const allocator_type& allocator = allocator_type()) 49 | : vector(allocator) 50 | { 51 | /**/ 52 | } 53 | #if 0 54 | template 55 | sorted_vector(InputIterator first, InputIterator last, 56 | const allocator_type& allocator = allocator_type()) 57 | : vector(first, last, allocator) 58 | { 59 | // @todo: sort! 60 | } 61 | #endif 62 | 63 | // @note: no non-const operator[], it may cause performance problems. 64 | // use explicit ways: insert or find. 65 | 66 | using Base::begin; 67 | using Base::end; 68 | using Base::size; 69 | using Base::empty; 70 | using Base::capacity; 71 | 72 | pair insert(const value_type& val) 73 | { 74 | RDE_ASSERT(invariant()); 75 | bool found(true); 76 | iterator it = lower_bound(val.first); 77 | RDE_ASSERT(it == end() || !m_compare(*it, val)); 78 | if (it == end() || m_compare(*it, val)) 79 | { 80 | it = Base::insert(it, val); 81 | found = false; 82 | } 83 | RDE_ASSERT(invariant()); 84 | return pair(it, !found); 85 | } 86 | // @extension 87 | RDE_FORCEINLINE 88 | pair insert(const key_type& k, const mapped_type& v) 89 | { 90 | return insert(value_type(k, v)); 91 | } 92 | 93 | iterator find(const key_type& k) 94 | { 95 | RDE_ASSERT(invariant()); 96 | iterator i(lower_bound(k)); 97 | if (i != end() && m_compare(k, *i)) 98 | { 99 | i = end(); 100 | } 101 | return i; 102 | } 103 | const_iterator find(const key_type& k) const 104 | { 105 | RDE_ASSERT(invariant()); 106 | const_iterator i(lower_bound(k)); 107 | if (i != end() && m_compare(k, *i)) 108 | { 109 | i = end(); 110 | } 111 | return i; 112 | } 113 | 114 | RDE_FORCEINLINE iterator erase(iterator it) 115 | { 116 | RDE_ASSERT(invariant()); 117 | return Base::erase(it); 118 | } 119 | size_type erase(const key_type& k) 120 | { 121 | iterator i(find(k)); 122 | if (i == end()) 123 | return 0; 124 | erase(i); 125 | RDE_ASSERT(invariant()); 126 | return 1; 127 | } 128 | 129 | using Base::clear; 130 | using Base::get_allocator; 131 | using Base::set_allocator; 132 | 133 | iterator lower_bound(const key_type& k) 134 | { 135 | return rde::lower_bound(begin(), end(), k, m_compare); 136 | } 137 | const_iterator lower_bound(const key_type& k) const 138 | { 139 | return rde::lower_bound(begin(), end(), k, m_compare); 140 | } 141 | iterator upper_bound(const key_type& k) 142 | { 143 | return rde::upper_bound(begin(), end(), k, m_compare); 144 | } 145 | const_iterator upper_bound(const key_type& k) const 146 | { 147 | return rde::upper_bound(begin(), end(), k, m_compare); 148 | } 149 | private: 150 | // @note: block copying for the time being. 151 | sorted_vector(const sorted_vector&); 152 | sorted_vector& operator=(const sorted_vector&); 153 | 154 | bool invariant() const 155 | { 156 | // Make sure we're sorted according to m_compare. 157 | const_iterator first = begin(); 158 | const_iterator last = end(); 159 | RDE_ASSERT(last >= first); 160 | if (first != last) 161 | { 162 | const_iterator next = first; 163 | if (++next != last) 164 | { 165 | RDE_ASSERT(m_compare(*first, *next)); 166 | first = next; 167 | } 168 | } 169 | return true; 170 | } 171 | 172 | internal::compare_func m_compare; 173 | }; 174 | 175 | } // namespace rde 176 | 177 | //----------------------------------------------------------------------------- 178 | #endif // #ifndef RDESTL_SORTED_VECTOR_H 179 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/intrusive_list.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_INTRUSIVE_LIST_H 2 | #define RDESTL_INTRUSIVE_LIST_H 3 | 4 | #include "rdestl/iterator.h" 5 | #include "rdestl/type_traits.h" 6 | 7 | namespace rde 8 | { 9 | 10 | //============================================================================= 11 | struct intrusive_list_node 12 | { 13 | intrusive_list_node() 14 | { 15 | next = prev = this; 16 | } 17 | bool in_list() const { return this != next; } 18 | 19 | intrusive_list_node* next; 20 | intrusive_list_node* prev; 21 | }; 22 | 23 | //============================================================================= 24 | template 25 | class intrusive_list_iterator 26 | { 27 | public: 28 | typedef Pointer pointer; 29 | typedef Reference reference; 30 | typedef bidirectional_iterator_tag iterator_category; 31 | 32 | intrusive_list_iterator(): m_node(0) {/**/} 33 | explicit intrusive_list_iterator(Pointer iterNode) 34 | : m_node(iterNode) 35 | { 36 | /**/ 37 | } 38 | 39 | Reference operator*() const 40 | { 41 | RDE_ASSERT(m_node); 42 | return *m_node; 43 | } 44 | Pointer operator->() const 45 | { 46 | return m_node; 47 | } 48 | Pointer node() const 49 | { 50 | return m_node; 51 | } 52 | 53 | intrusive_list_iterator& operator++() 54 | { 55 | m_node = static_cast(m_node->next); 56 | return *this; 57 | } 58 | intrusive_list_iterator& operator--() 59 | { 60 | m_node = static_cast(m_node->prev); 61 | return *this; 62 | } 63 | intrusive_list_iterator operator++(int) 64 | { 65 | intrusive_list_iterator copy(*this); 66 | ++(*this); 67 | return copy; 68 | } 69 | intrusive_list_iterator operator--(int) 70 | { 71 | intrusive_list_iterator copy(*this); 72 | --(*this); 73 | return copy; 74 | } 75 | 76 | bool operator==(const intrusive_list_iterator& rhs) const 77 | { 78 | return rhs.m_node == m_node; 79 | } 80 | bool operator!=(const intrusive_list_iterator& rhs) const 81 | { 82 | return !(rhs == *this); 83 | } 84 | 85 | private: 86 | Pointer m_node; 87 | }; 88 | 89 | //============================================================================= 90 | class intrusive_list_base 91 | { 92 | public: 93 | typedef size_t size_type; 94 | 95 | intrusive_list_base(); 96 | 97 | void pop_back() 98 | { 99 | unlink(m_root.prev); 100 | } 101 | void pop_front() 102 | { 103 | unlink(m_root.next); 104 | } 105 | 106 | // @note: allow for constant complexity way of checking this 107 | // (at a cost of additional variable)? 108 | size_type size() const; 109 | bool empty() const { return !m_root.in_list(); } 110 | 111 | protected: 112 | // links 'node' before 'nextNode' 113 | static void link(intrusive_list_node* node, intrusive_list_node* nextNode); 114 | static void unlink(intrusive_list_node* node); 115 | 116 | intrusive_list_node m_root; 117 | 118 | private: 119 | intrusive_list_base(const intrusive_list_base&); 120 | intrusive_list_base& operator=(const intrusive_list_base&); 121 | }; 122 | 123 | //============================================================================= 124 | // Can store pointers only! 125 | template 126 | class intrusive_list : public intrusive_list_base 127 | { 128 | public: 129 | typedef T node_type; 130 | typedef T value_type; 131 | typedef intrusive_list_iterator iterator; 132 | typedef intrusive_list_iterator const_iterator; 133 | 134 | void push_back(value_type* v) 135 | { 136 | link(v, &m_root); 137 | } 138 | void push_front(value_type* v) 139 | { 140 | link(v, m_root.next); 141 | } 142 | 143 | iterator begin() { return iterator(upcast(m_root.next)); } 144 | const_iterator begin() const { return const_iterator(upcast(m_root.next)); } 145 | iterator end() { return iterator(upcast(&m_root)); } 146 | const_iterator end() const { return const_iterator(upcast(&m_root)); } 147 | 148 | value_type* front() { return upcast(m_root.next); } 149 | const value_type* front() const { return upcast(m_root.next); } 150 | value_type* back() { return upcast(m_root.prev); } 151 | const value_type* back() const { return upcast(m_root.prev); } 152 | 153 | iterator insert(iterator pos, value_type* v) 154 | { 155 | link(v, pos.node()); 156 | return iterator(v); 157 | } 158 | iterator erase(iterator it) 159 | { 160 | iterator itErase(it); 161 | ++it; 162 | unlink(itErase.node()); 163 | return it; 164 | } 165 | iterator erase(iterator first, iterator last) 166 | { 167 | while (first != last) 168 | first = erase(first); 169 | return first; 170 | } 171 | 172 | void clear() 173 | { 174 | erase(begin(), end()); 175 | } 176 | 177 | // O(1) 178 | static void remove(value_type* v) 179 | { 180 | unlink(v); 181 | } 182 | 183 | private: 184 | static RDE_FORCEINLINE node_type* upcast(intrusive_list_node* n) 185 | { 186 | return static_cast(n); 187 | } 188 | static RDE_FORCEINLINE const node_type* upcast(const intrusive_list_node* n) 189 | { 190 | return static_cast(n); 191 | } 192 | }; 193 | 194 | } // namespace rde 195 | 196 | //----------------------------------------------------------------------------- 197 | #endif // #ifndef RDESTL_INTRUSIVE_LIST_H 198 | -------------------------------------------------------------------------------- /src/rdestl/rdestl/fixed_vector.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FIXED_VECTOR_H 2 | #define RDESTL_FIXED_VECTOR_H 3 | 4 | #include "rdestl/vector.h" 5 | 6 | #define RDESTL_RECORD_WATERMARKS 0 7 | 8 | // @TODO Wont work on 64-bit! 9 | // 4267 -- conversion from size_t to int. 10 | #pragma warning(push) 11 | #pragma warning(disable: 4267) 12 | 13 | namespace rde 14 | { 15 | //============================================================================= 16 | template 17 | struct fixed_vector_storage 18 | { 19 | explicit fixed_vector_storage(const TAllocator& allocator) 20 | : m_begin((T*)&m_data[0]), 21 | m_end(m_begin), 22 | m_capacity(TCapacity), 23 | m_allocator(allocator) 24 | #if RDESTL_RECORD_WATERMARKS 25 | , m_max_size(0) 26 | #endif 27 | { 28 | /**/ 29 | } 30 | 31 | // @note Cant shrink 32 | void reallocate(base_vector::size_type newCapacity, bool /*canShrink*/ = false) 33 | { 34 | if (newCapacity > m_capacity) 35 | { 36 | if (!TGrowOnOverflow) 37 | { 38 | RDE_ASSERT(!"fixed_vector cannot grow"); 39 | // @TODO: do something more spectacular here... do NOT throw exception, tho :) 40 | } 41 | 42 | T* newBegin = static_cast(m_allocator.allocate(newCapacity * sizeof(T))); 43 | const base_vector::size_type currSize((size_t)(m_end - m_begin)); 44 | const base_vector::size_type newSize = currSize < newCapacity ? 45 | currSize : newCapacity; 46 | // Copy old data if needed. 47 | if (m_begin) 48 | { 49 | rde::copy_construct_n(m_begin, newSize, newBegin); 50 | destroy(m_begin, currSize); 51 | } 52 | m_begin = newBegin; 53 | m_end = m_begin + newSize; 54 | m_capacity = newCapacity; 55 | record_high_watermark(); 56 | RDE_ASSERT(invariant()); 57 | } 58 | } 59 | 60 | // Reallocates memory, doesnt copy contents of old buffer. 61 | void reallocate_discard_old(base_vector::size_type newCapacity) 62 | { 63 | if (newCapacity > m_capacity) 64 | { 65 | if (!TGrowOnOverflow) 66 | { 67 | RDE_ASSERT(!"fixed_vector cannot grow"); 68 | } 69 | T* newBegin = static_cast(m_allocator.allocate(newCapacity * sizeof(T))); 70 | const base_vector::size_type currSize((size_t)(m_end - m_begin)); 71 | if (m_begin) 72 | destroy(m_begin, currSize); 73 | m_begin = newBegin; 74 | m_end = m_begin + currSize; 75 | record_high_watermark(); 76 | m_capacity = newCapacity; 77 | } 78 | RDE_ASSERT(invariant()); 79 | } 80 | RDE_FORCEINLINE void destroy(T* ptr, base_vector::size_type n) 81 | { 82 | rde::destruct_n(ptr, n); 83 | if ((unsigned char*)ptr != &m_data[0]) 84 | m_allocator.deallocate(ptr, n * sizeof(T)); 85 | } 86 | bool invariant() const 87 | { 88 | return m_end >= m_begin; 89 | } 90 | RDE_FORCEINLINE void record_high_watermark() 91 | { 92 | #if RDESTL_RECORD_WATERMARKS 93 | const base_vector::size_type curr_size((size_t)(m_end - m_begin)); 94 | if (curr_size > m_max_size) 95 | m_max_size = curr_size; 96 | #endif 97 | } 98 | base_vector::size_type get_high_watermark() const 99 | { 100 | #if RDESTL_RECORD_WATERMARKS 101 | return m_max_size; 102 | #else 103 | return m_capacity; // ??? 104 | #endif 105 | } 106 | 107 | T* m_begin; 108 | T* m_end; 109 | typedef char ERR_InvalidUCharSize[sizeof(unsigned char) == 1 ? 1 : -1]; 110 | // Not T[], because we need uninitialized memory. 111 | // @todo: solve potential alignment problems. 112 | unsigned char m_data[TCapacity * sizeof(T)]; 113 | // @todo: m_capacity is not really needed for containers that 114 | // cant overflow. 115 | base_vector::size_type m_capacity; 116 | TAllocator m_allocator; 117 | #if RDESTL_RECORD_WATERMARKS 118 | base_vector::size_type m_max_size; 119 | #endif 120 | }; 121 | 122 | //============================================================================= 123 | template 125 | class fixed_vector : public vector > 127 | { 128 | typedef vector > super; 130 | public: 131 | explicit fixed_vector(const allocator_type& allocator = allocator_type()) 132 | : super(allocator) 133 | { 134 | /**/ 135 | } 136 | explicit fixed_vector(size_type initialSize, const allocator_type& allocator = allocator_type()) 137 | : super(initialSize, allocator) 138 | { 139 | /**/ 140 | } 141 | fixed_vector(const T* first, const T* last, const allocator_type& allocator = allocator_type()) 142 | : super(first, last, allocator) 143 | { 144 | /**/ 145 | } 146 | // @note: allocator is not copied from rhs. 147 | // @note: will not perform default constructor for newly created objects. 148 | fixed_vector(const fixed_vector& rhs, const allocator_type& allocator = allocator_type()) 149 | : super(rhs, allocator) 150 | { 151 | /**/ 152 | } 153 | 154 | fixed_vector& operator=(const fixed_vector& rhs) 155 | { 156 | if (&rhs != this) 157 | { 158 | super& superThis = *this; 159 | superThis = rhs; 160 | } 161 | return *this; 162 | } 163 | }; 164 | 165 | #pragma warning(pop) 166 | 167 | } // rde 168 | 169 | #endif // #ifndef RDESTL_FIXED_VECTOR_H 170 | --------------------------------------------------------------------------------