From 97b2282b40ee304f03aa7fe7a2999e1d060d44e6 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 19 Jun 2017 13:32:50 -0700 Subject: [PATCH] edits --- src/Encoders/elementencoding.c | 9 +++++++++ src/Encoders/elementencoding.h | 10 ++++++++++ src/Encoders/naiveelementencoder.c | 9 +++++++-- src/common.h | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Encoders/elementencoding.c b/src/Encoders/elementencoding.c index 8056812..fb2ce4a 100644 --- a/src/Encoders/elementencoding.c +++ b/src/Encoders/elementencoding.c @@ -15,6 +15,15 @@ void deleteElementEncoding(ElementEncoding *This) { ourfree(This->variables); if (This->encodingArray!=NULL) ourfree(This->encodingArray); + if (This->inUseArray!=NULL) + ourfree(This->inUseArray); ourfree(This); } +void allocEncodingArrayElement(ElementEncoding *This, uint size) { + This->encodingArray=ourcalloc(1, sizeof(uint64_t)*size); +} + +void allocInUseArrayElement(ElementEncoding *This, uint size) { + This->inUseArray=ourcalloc(1, size >> 6); +} diff --git a/src/Encoders/elementencoding.h b/src/Encoders/elementencoding.h index d6de95a..8d142da 100644 --- a/src/Encoders/elementencoding.h +++ b/src/Encoders/elementencoding.h @@ -13,11 +13,21 @@ struct ElementEncoding { Element * element; Constraint ** variables; /* List Variables Used To Encode Element */ uint64_t * encodingArray; /* List the Variables in the appropriate order */ + uint64_t * inUseArray; /* Bitmap to track variables in use */ uint numVars; /* Number of variables */ }; ElementEncoding * allocElementEncoding(ElementEncodingType type, Element *element); void deleteElementEncoding(ElementEncoding *This); void baseBinaryIndexElementAssign(ElementEncoding *This); +void allocEncodingArrayElement(ElementEncoding *This, uint size); +void allocInUseArrayElement(ElementEncoding *This, uint size); +inline bool isinUseElement(ElementEncoding *This, uint offset) { + return (This->inUseArray[(offset>>6)] >> (offset & 63)) &0x1; +} + +inline void setInUseElement(ElementEncoding *This, uint offset) { + This->inUseArray[(offset>>6)] |= 1 << (offset & 63); +} #endif diff --git a/src/Encoders/naiveelementencoder.c b/src/Encoders/naiveelementencoder.c index ec3be7d..4d52235 100644 --- a/src/Encoders/naiveelementencoder.c +++ b/src/Encoders/naiveelementencoder.c @@ -4,15 +4,20 @@ #include "set.h" #include "common.h" #include "struct.h" +#include void baseBinaryIndexElementAssign(ElementEncoding *This) { Element * element=This->element; Set * set=element->set; ASSERT(set->isRange==false); uint size=getSizeVectorInt(set->members); - This->encodingArray=ourmalloc(sizeof(uint64_t)*size); + uint encSize=NEXTPOW2(size); + allocEncodingArrayElement(This, encSize); + allocInUseArrayElement(This, encSize); + for(uint i=0;iencodingArray[i]=getVectorInt(set->members, i); + setInUseElement(This, i); } - This->type=BINARYINDEX; } + diff --git a/src/common.h b/src/common.h index d4d86c6..9b78485 100644 --- a/src/common.h +++ b/src/common.h @@ -27,7 +27,7 @@ extern int switch_alloc; #define model_print_err(fmt, ...) do { model_dprintf(model_err, fmt, ## __VA_ARGS__); } while (0) - +#define NEXTPOW2(x) (1<<(sizeof(uint)*8-__builtin_clz(x-1))) #ifdef CONFIG_DEBUG #define DEBUG(fmt, ...) do { model_print("*** %15s:%-4d %25s() *** " fmt, __FILE__, __LINE__, __func__, ## __VA_ARGS__); } while (0) -- 2.34.1