From 79d5f6b621df9fea88c63365e7aa5d5b85308d93 Mon Sep 17 00:00:00 2001
From: Arne Goedeke <el@laramies.com>
Date: Sun, 16 Jun 2013 11:53:36 +0200
Subject: [PATCH] CritBit: use type bit fields to allow unions

---
 src/post_modules/CritBit/bignumtree.cmod   | 2 +-
 src/post_modules/CritBit/floattree.cmod    | 2 +-
 src/post_modules/CritBit/inttree.cmod      | 4 ++--
 src/post_modules/CritBit/iterator_source.H | 4 ++--
 src/post_modules/CritBit/stringtree.cmod   | 2 +-
 src/post_modules/CritBit/tree_header.H     | 6 +++---
 src/post_modules/CritBit/tree_source.H     | 2 +-
 7 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/post_modules/CritBit/bignumtree.cmod b/src/post_modules/CritBit/bignumtree.cmod
index 303f4c9ba1..52e804a508 100644
--- a/src/post_modules/CritBit/bignumtree.cmod
+++ b/src/post_modules/CritBit/bignumtree.cmod
@@ -37,7 +37,7 @@ PIKECLASS BigNumTree {
 #cmod_define iterator_class Iterator
 #cmod_define tree_class BigNumTree
 #cmod_define cmod_OBJ2_TREE OBJ2_BIGNUMTREE
-#cmod_define T_KEY PIKE_T_OBJECT
+#cmod_define T_KEY BIT_OBJECT
 #cmod_define key_ptype bignum
 #cmod_define sval_type object
 /*
diff --git a/src/post_modules/CritBit/floattree.cmod b/src/post_modules/CritBit/floattree.cmod
index fded0699f3..d30878c93f 100644
--- a/src/post_modules/CritBit/floattree.cmod
+++ b/src/post_modules/CritBit/floattree.cmod
@@ -21,7 +21,7 @@ PIKECLASS FloatTree {
 #cmod_define iterator_class Iterator
 #cmod_define tree_class FloatTree
 #cmod_define cmod_OBJ2_TREE OBJ2_FLOATTREE
-#cmod_define T_KEY (PIKE_T_FLOAT|PIKE_T_INT)
+#cmod_define T_KEY (BIT_FLOAT|BIT_INT)
 #cmod_define key_ptype float|int
 #cmod_define sample_key 12.0
 #cmod_define sample_keys ({ 80.4, 99.9, 14.2 })
diff --git a/src/post_modules/CritBit/inttree.cmod b/src/post_modules/CritBit/inttree.cmod
index 0fb75550af..b972635528 100644
--- a/src/post_modules/CritBit/inttree.cmod
+++ b/src/post_modules/CritBit/inttree.cmod
@@ -27,7 +27,7 @@ PIKECLASS IntTree {
 #cmod_define iterator_class Iterator
 #cmod_define tree_class IntTree
 #cmod_define cmod_OBJ2_TREE OBJ2_INTTREE
-#cmod_define T_KEY PIKE_T_INT
+#cmod_define T_KEY BIT_INT
 #cmod_define key_ptype int
 #cmod_define sval_type integer
 #cmod_define sample_key 12
@@ -97,7 +97,7 @@ PIKECLASS IPv4Tree {
 #cmod_define iterator_class Iterator
 #cmod_define tree_class IPv4Tree
 #cmod_define cmod_OBJ2_TREE OBJ2_IPV4TREE
-#cmod_define T_KEY PIKE_T_STRING
+#cmod_define T_KEY BIT_STRING
 #cmod_define key_ptype string
 #cmod_define sval_type string
 #cmod_define sample_key "127.0.0.0/8"
diff --git a/src/post_modules/CritBit/iterator_source.H b/src/post_modules/CritBit/iterator_source.H
index 8045b5d44e..2d5b548cdd 100644
--- a/src/post_modules/CritBit/iterator_source.H
+++ b/src/post_modules/CritBit/iterator_source.H
@@ -164,7 +164,7 @@
 			    apply_low(tree, encode_fun, 1);
 			    assign_svalue(stop, Pike_sp-1);
 			    pop_stack();
-			    if (!(stop->type == T_KEY))
+			    if (!((1<<stop->type) & T_KEY))
 				SIMPLE_BAD_ARG_ERROR("create", 3, cmod_STRFY_EVAL(key_ptype));
 			}
 			THIS->stop = CB_LOW_KEY_FROM_SVALUE(stop);
@@ -179,7 +179,7 @@
 			    apply_low(tree, encode_fun, 1);
 			    assign_svalue(start, Pike_sp-1);
 			    pop_stack();
-			    if (!(start->type == T_KEY))
+			    if (!((1<<start->type) & T_KEY))
 				SIMPLE_BAD_ARG_ERROR("create", 2, cmod_STRFY_EVAL(key_ptype));
 			}
 			s = CB_LOW_KEY_FROM_SVALUE(start);
diff --git a/src/post_modules/CritBit/stringtree.cmod b/src/post_modules/CritBit/stringtree.cmod
index 48858d7413..ae0a8409b1 100644
--- a/src/post_modules/CritBit/stringtree.cmod
+++ b/src/post_modules/CritBit/stringtree.cmod
@@ -42,7 +42,7 @@ PIKECLASS StringTree {
 #cmod_define iterator_class Iterator
 #cmod_define tree_class StringTree
 #cmod_define cmod_OBJ2_TREE OBJ2_STRINGTREE
-#cmod_define T_KEY PIKE_T_STRING
+#cmod_define T_KEY BIT_STRING
 #cmod_define key_ptype string
 #cmod_define sval_type string
 #cmod_define sample_key "foo"
diff --git a/src/post_modules/CritBit/tree_header.H b/src/post_modules/CritBit/tree_header.H
index 016cf971a9..eda717d335 100644
--- a/src/post_modules/CritBit/tree_header.H
+++ b/src/post_modules/CritBit/tree_header.H
@@ -73,7 +73,7 @@ DOCEND()
 #undef CB_CHECK_KEY
 #define CB_CHECK_KEY(svalue, fun, num)	do {			\
     CB_TRANSFORM_KEY(svalue);					\
-    if (!((svalue)->type == T_KEY))   				\
+    if (!((1<<(svalue)->type) & T_KEY))   			\
 	SIMPLE_BAD_ARG_ERROR(fun, (num), STRFY(key_ptype));	\
 } while(0)
 #undef CB_PUSH_TRANSFORM_KEY
@@ -91,12 +91,12 @@ TREE_CLASSIFY(_transform_svalue_to_key)(const struct svalue * s) {
     if (THIS->encode_fun >= 0) {
 	push_svalue(s);
 	apply_low(Pike_fp->current_object, THIS->encode_fun, 1);
-	if (!(Pike_sp[-1].type == T_KEY))
+	if (!((1<<Pike_sp[-1].type) & T_KEY))
 	    Pike_error("encode_key() is expected to return type " cmod_STRFY_EVAL(key_ptype) ".\n");
 	key = CB_LOW_KEY_FROM_SVALUE(Pike_sp-1);
 	pop_stack();
     } else {
-	if (!(s->type == T_KEY)) Pike_error("Expected type " cmod_STRFY_EVAL(key_ptype) ".\n");
+	if (!((1<<s->type) & T_KEY)) Pike_error("Expected type " cmod_STRFY_EVAL(key_ptype) ".\n");
 	key = CB_LOW_KEY_FROM_SVALUE(s);
     }
     return key;
diff --git a/src/post_modules/CritBit/tree_source.H b/src/post_modules/CritBit/tree_source.H
index 430b9c449a..b6b06bd3eb 100644
--- a/src/post_modules/CritBit/tree_source.H
+++ b/src/post_modules/CritBit/tree_source.H
@@ -279,7 +279,7 @@ DOCEND()
      */
     PIKEFUN mixed `[](mixed key) {
 	CB_TRANSFORM_KEY(key);
-	if (key->type == T_KEY) {
+	if ((1<<key->type) & T_KEY) {
 	    cb_node_t n;
 	    cb_key k = CB_LOW_KEY_FROM_SVALUE(key);
 	    pop_stack();
-- 
GitLab