Permalink
Browse files

Range Search Support For Floats

  • Loading branch information...
1 parent ee67d12 commit a6b671b0e0b039d3b2149af8d830a3c793c075c8 Efe committed Sep 17, 2012
View
@@ -0,0 +1 @@
+-pedantic -std=c++98 -Wabi -Wall -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Weffc++ -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Winline -Woverloaded-virtual -Wshadow -Wsign-promo -Wstrict-overflow -Wstrict-aliasing -Wswitch-default -Wswitch-enum -Wunsafe-loop-optimizations -Wwrite-strings -Wno-long-long
View
@@ -187,8 +187,8 @@ main(int argc, char* argv[])
hyperclient_range_query rn;
rn.attr = "num";
- rn.lower = num;
- rn.upper = num + 1;
+ rn.lower_t.i = num;
+ rn.upper_t.i = num + 1;
validate_search(&cl, num, space, NULL, 0, &rn, 1, "range");
}
@@ -1027,14 +1027,14 @@ hyperclient :: prepare_searchop(const char* space,
return -1 - eq_sz - i;
}
- if (sc->attrs[attrnum].type != HYPERDATATYPE_INT64)
+ if ((sc->attrs[attrnum].type != HYPERDATATYPE_INT64) && (sc->attrs[attrnum].type != HYPERDATATYPE_FLOAT))
{
*status = HYPERCLIENT_WRONGTYPE;
return -1 - eq_sz - i;
}
seen.set(attrnum);
- s->range_set(attrnum, rn[i].lower, rn[i].upper);
+ s->range_set(attrnum, rn[i].lower_t.i, rn[i].upper_t.i);
}
if (attr)
@@ -102,11 +102,18 @@ struct hyperclient_map_attribute
enum hyperdatatype value_datatype;
};
+union hyperclient_range_query_union
+{
+ double d;
+ uint64_t i;
+};
+
+
struct hyperclient_range_query
{
const char* attr;
- uint64_t lower;
- uint64_t upper;
+ union hyperclient_range_query_union lower_t;
+ union hyperclient_range_query_union upper_t;
};
/* HyperClient returncode occupies [8448, 8576) */
@@ -96,11 +96,15 @@ cdef extern from "../hyperclient.h":
size_t value_sz
hyperdatatype value_datatype
+ cdef union hyperclient_range_query_union:
+ double d
+ uint64_t i
+
cdef struct hyperclient_range_query:
char* attr
unsigned long attr_sz
- uint64_t lower
- uint64_t upper
+ hyperclient_range_query_union lower_t
+ hyperclient_range_query_union upper_t
cdef enum hyperclient_returncode:
HYPERCLIENT_SUCCESS = 8448
@@ -924,31 +928,41 @@ cdef _predicate_to_c(dict predicate,
hyperclient_range_query** rn, size_t* rn_sz):
cdef uint64_t lower
cdef uint64_t upper
+ cdef double lower_d
+ cdef double upper_d
equalities = []
ranges = []
for attr, params in predicate.iteritems():
if isinstance(params, tuple):
- (lower, upper) = params
- ranges.append((attr, lower, upper))
+ if isinstance(params[0], (int, long)):
+ (lower, upper) = params
+ ranges.append((attr, lower, upper))
+ elif isinstance(params[0], float):
+ (lower_d, upper_d) = params
+ ranges.append((attr, lower_d, upper_d))
elif isinstance(params, int):
equalities.append((attr, params))
elif isinstance(params, bytes):
equalities.append((attr, params))
elif isinstance(params, float):
equalities.append((attr, params))
else:
- errstr = "Attribute '{attr}' has incorrect type (expected int, float, (int, int) or bytes, got {type}"
+ errstr = "Attribute '{attr}' has incorrect type (expected int, float, (int, int), (float, float) or bytes, got {type}"
raise TypeError(errstr.format(attr=attr, type=str(type(params))[7:-2]))
eq_sz[0] = len(equalities)
rn_sz[0] = len(ranges)
rn[0] = <hyperclient_range_query*> malloc(sizeof(hyperclient_range_query) * rn_sz[0])
if rn[0] == NULL:
raise MemoryError()
backings = _dict_to_attrs(equalities, eq)
- for i, (attr, lower, upper) in enumerate(ranges):
+ for i, (attr, bottom, top) in enumerate(ranges):
rn[i].attr = attr
- rn[i].lower = lower
- rn[i].upper = upper
+ if isinstance(bottom, (int, long)):
+ rn[i].lower_t.i = bottom
+ rn[i].upper_t.i = top
+ elif isinstance(bottom, float):
+ rn[i].lower_t.d = bottom
+ rn[i].upper_t.d = top
cdef class DeferredGroupDel(Deferred):
@@ -998,7 +998,7 @@ hyperdex :: configuration_parser :: attrs_to_hashfuncs(const subspaceid& ssi,
hfuncs.push_back(hyperspacehashing::RANGE);
break;
case HYPERDATATYPE_FLOAT:
- hfuncs.push_back(hyperspacehashing::EQUALITY);
+ hfuncs.push_back(hyperspacehashing::RANGE);
break;
case HYPERDATATYPE_GENERIC:
case HYPERDATATYPE_LIST_GENERIC:
@@ -57,4 +57,4 @@ hyperspacehashing :: lendian(const e::slice& buf)
uint64_t ret;
e::unpack64le(tmp, &ret);
return ret;
-}
+}
@@ -49,7 +49,6 @@ cityhash(const e::slice& buf);
uint64_t
lendian(const e::slice& buf);
-
} // namespace hyperspacehashing
#endif // hyperspacehashing_hashes_internal_h_
@@ -34,9 +34,9 @@ namespace hyperspacehashing
// 0 is reserved for internal use.
enum hash_t
{
- EQUALITY = 1,
- RANGE = 2,
- NONE = 3
+ EQUALITY = 1,
+ RANGE = 2,
+ NONE = 3
};
} // namespace hyperspacehashing

0 comments on commit a6b671b

Please sign in to comment.