Skip to content

Commit

Permalink
Cleanup hash table code
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdrake committed May 30, 2015
1 parent 4c836c2 commit a12a508
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 96 deletions.
2 changes: 1 addition & 1 deletion extension/boolexpr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ all: bld/test/run bld/cover/run bld/lib/libboolexpr.a
# Source Code
#===============================================================================

BOOLEXPR_HDRS := boolexpr.h
BOOLEXPR_HDRS := boolexpr.h dict.h set.h primes-inl.c

BOOLEXPR_SRCS := \
argset.c \
Expand Down
13 changes: 0 additions & 13 deletions extension/boolexpr/boolexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,6 @@ struct BoolExprVector {
};


struct BoolExprDictItem {
struct BoolExpr *key;
struct BoolExpr *val;
struct BoolExprDictItem *tail;
};


struct BoolExprDict {
size_t _pridx;

Expand All @@ -188,12 +181,6 @@ struct BoolExprDict {
};


struct BoolExprSetItem {
struct BoolExpr *key;
struct BoolExprSetItem *tail;
};


struct BoolExprSet {
size_t _pridx;

Expand Down
43 changes: 2 additions & 41 deletions extension/boolexpr/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,11 @@
#include <stddef.h>
#include <stdlib.h>

#include "dict.h"
#include "boolexpr.h"


#define MAX_LOAD 1.5


/*
** From: http://planetmath.org/goodhashtableprimes
*/

#define MIN_IDX 4
#define MAX_IDX 30

static size_t _primes[] = {
0, 0, 0, 0,

/* (2^4, 2^5) */ 23,
/* (2^5, 2^6) */ 53,
/* (2^6, 2^7) */ 97,
/* (2^7, 2^8) */ 193,
/* (2^8, 2^9) */ 389,
/* (2^9, 2^10) */ 769,
/* (2^10, 2^11) */ 1543,
/* (2^11, 2^12) */ 3079,
/* (2^12, 2^13) */ 6151,
/* (2^13, 2^14) */ 12289,
/* (2^14, 2^15) */ 24593,
/* (2^15, 2^16) */ 49157,
/* (2^16, 2^17) */ 98317,
/* (2^17, 2^18) */ 196613,
/* (2^18, 2^19) */ 393241,
/* (2^19, 2^20) */ 786433,
/* (2^20, 2^21) */ 1572869,
/* (2^21, 2^22) */ 3145739,
/* (2^22, 2^23) */ 6291469,
/* (2^23, 2^24) */ 12582917,
/* (2^24, 2^25) */ 25165843,
/* (2^25, 2^26) */ 50331653,
/* (2^26, 2^27) */ 100663319,
/* (2^27, 2^28) */ 201326611,
/* (2^28, 2^29) */ 402653189,
/* (2^29, 2^30) */ 805306457,
/* (2^30, 2^31) */ 1610612741,
};
#include "primes-inl.c"


static size_t
Expand Down
26 changes: 26 additions & 0 deletions extension/boolexpr/dict.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
** Filename: dict.h
*/


#ifndef DICT_H
#define DICT_H


/* Maximum load allowed before enlargement */
#define MAX_LOAD 1.5

/* Min/Max indices in the primes table */
#define MIN_IDX 4
#define MAX_IDX 30


struct BoolExprDictItem {
struct BoolExpr *key;
struct BoolExpr *val;
struct BoolExprDictItem *tail;
};


#endif /* DICT_H */

41 changes: 41 additions & 0 deletions extension/boolexpr/primes-inl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
** Filename: primes-inl.c
*/

static size_t _primes[] = {
/* (2^0, 2^1) */ 2,
/* (2^1, 2^2) */ 3,
/* (2^2, 2^3) */ 7,
/* (2^3, 2^4) */ 13,
/* (2^4, 2^5) */ 23,

/* From: http://planetmath.org/goodhashtableprimes */

/* (2^5, 2^6) */ 53,
/* (2^6, 2^7) */ 97,
/* (2^7, 2^8) */ 193,
/* (2^8, 2^9) */ 389,
/* (2^9, 2^10) */ 769,
/* (2^10, 2^11) */ 1543,
/* (2^11, 2^12) */ 3079,
/* (2^12, 2^13) */ 6151,
/* (2^13, 2^14) */ 12289,
/* (2^14, 2^15) */ 24593,
/* (2^15, 2^16) */ 49157,
/* (2^16, 2^17) */ 98317,
/* (2^17, 2^18) */ 196613,
/* (2^18, 2^19) */ 393241,
/* (2^19, 2^20) */ 786433,
/* (2^20, 2^21) */ 1572869,
/* (2^21, 2^22) */ 3145739,
/* (2^22, 2^23) */ 6291469,
/* (2^23, 2^24) */ 12582917,
/* (2^24, 2^25) */ 25165843,
/* (2^25, 2^26) */ 50331653,
/* (2^26, 2^27) */ 100663319,
/* (2^27, 2^28) */ 201326611,
/* (2^28, 2^29) */ 402653189,
/* (2^29, 2^30) */ 805306457,
/* (2^30, 2^31) */ 1610612741,
};

43 changes: 2 additions & 41 deletions extension/boolexpr/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,11 @@
#include <stddef.h>
#include <stdlib.h>

#include "set.h"
#include "boolexpr.h"


#define MAX_LOAD 1.5


/*
** From: http://planetmath.org/goodhashtableprimes
*/

#define MIN_IDX 4
#define MAX_IDX 30

static size_t _primes[] = {
0, 0, 0, 0,

/* (2^4, 2^5) */ 23,
/* (2^5, 2^6) */ 53,
/* (2^6, 2^7) */ 97,
/* (2^7, 2^8) */ 193,
/* (2^8, 2^9) */ 389,
/* (2^9, 2^10) */ 769,
/* (2^10, 2^11) */ 1543,
/* (2^11, 2^12) */ 3079,
/* (2^12, 2^13) */ 6151,
/* (2^13, 2^14) */ 12289,
/* (2^14, 2^15) */ 24593,
/* (2^15, 2^16) */ 49157,
/* (2^16, 2^17) */ 98317,
/* (2^17, 2^18) */ 196613,
/* (2^18, 2^19) */ 393241,
/* (2^19, 2^20) */ 786433,
/* (2^20, 2^21) */ 1572869,
/* (2^21, 2^22) */ 3145739,
/* (2^22, 2^23) */ 6291469,
/* (2^23, 2^24) */ 12582917,
/* (2^24, 2^25) */ 25165843,
/* (2^25, 2^26) */ 50331653,
/* (2^26, 2^27) */ 100663319,
/* (2^27, 2^28) */ 201326611,
/* (2^28, 2^29) */ 402653189,
/* (2^29, 2^30) */ 805306457,
/* (2^30, 2^31) */ 1610612741,
};
#include "primes-inl.c"


static size_t
Expand Down
25 changes: 25 additions & 0 deletions extension/boolexpr/set.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
** Filename: set.h
*/


#ifndef SET_H
#define SET_H


/* Maximum load allowed before enlargement */
#define MAX_LOAD 1.5

/* Min/Max indices in the primes table */
#define MIN_IDX 4
#define MAX_IDX 30


struct BoolExprSetItem {
struct BoolExpr *key;
struct BoolExprSetItem *tail;
};


#endif /* SET_H */

0 comments on commit a12a508

Please sign in to comment.