You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2016/04/14 01:06:37 UTC
[1/7] lucy git commit: Adapt Go bindings for BitVector width change.
Repository: lucy
Updated Branches:
refs/heads/master 67c6fec0b -> 54841aa79
Adapt Go bindings for BitVector width change.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/42640a6f
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/42640a6f
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/42640a6f
Branch: refs/heads/master
Commit: 42640a6f408adb78556532b6a43f4d71cd842caa
Parents: 71d7edd
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 6 18:16:57 2016 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Apr 12 21:38:55 2016 -0700
----------------------------------------------------------------------
go/lucy/object.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/42640a6f/go/lucy/object.go
----------------------------------------------------------------------
diff --git a/go/lucy/object.go b/go/lucy/object.go
index 356f255..de0040f 100644
--- a/go/lucy/object.go
+++ b/go/lucy/object.go
@@ -28,11 +28,11 @@ import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
func (bv *BitVectorIMP) ToArray() []bool {
cap := bv.getCapacity()
- if cap != uint32(int(cap)) {
+ if cap != uintptr(int(cap)) {
panic(fmt.Sprintf("Capacity of range: %d", cap))
}
bools := make([]bool, int(cap))
- for i := uint32(0); i < cap; i++ {
+ for i := uintptr(0); i < cap; i++ {
bools[i] = bv.Get(i)
}
return bools
[2/7] lucy git commit: Adapt for changed BitVector return value APIs.
Posted by ma...@apache.org.
Adapt for changed BitVector return value APIs.
BitVec counts and sizes are now measured in size_t not uint32_t.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/71d7edd2
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/71d7edd2
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/71d7edd2
Branch: refs/heads/master
Commit: 71d7edd2c2c1eeaf1a1b4e8b9a01a621b53180d4
Parents: e03b8c7
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 6 18:00:30 2016 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Apr 12 21:38:55 2016 -0700
----------------------------------------------------------------------
core/Lucy/Index/BitVecDelDocs.c | 4 ++--
core/Lucy/Index/DeletionsWriter.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/71d7edd2/core/Lucy/Index/BitVecDelDocs.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/BitVecDelDocs.c b/core/Lucy/Index/BitVecDelDocs.c
index 4cd1e50..30dcb98 100644
--- a/core/Lucy/Index/BitVecDelDocs.c
+++ b/core/Lucy/Index/BitVecDelDocs.c
@@ -40,9 +40,9 @@ BitVecDelDocs_init(BitVecDelDocs *self, Folder *folder,
RETHROW(error);
}
// Cast away const-ness of buffer as we have no immutable BitVector.
- int32_t len = (int32_t)InStream_Length(ivars->instream);
+ int64_t len = InStream_Length(ivars->instream);
ivars->bits = (uint8_t*)InStream_Buf(ivars->instream, len);
- ivars->cap = (uint32_t)(len * 8);
+ ivars->cap = (size_t)(len * 8);
return self;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/71d7edd2/core/Lucy/Index/DeletionsWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/DeletionsWriter.c b/core/Lucy/Index/DeletionsWriter.c
index adf0d53..c9c8899 100644
--- a/core/Lucy/Index/DeletionsWriter.c
+++ b/core/Lucy/Index/DeletionsWriter.c
@@ -152,8 +152,8 @@ DefDelWriter_Finish_IMP(DefaultDeletionsWriter *self) {
if (ivars->updated[i]) {
BitVector *deldocs = (BitVector*)Vec_Fetch(ivars->bit_vecs, i);
int32_t doc_max = SegReader_Doc_Max(seg_reader);
- uint32_t byte_size = (((uint32_t)doc_max + 1) + 7) / 8;
- uint32_t new_max = byte_size * 8 - 1;
+ size_t byte_size = (((size_t)doc_max + 1) + 7) / 8;
+ size_t new_max = byte_size * 8 - 1;
String *filename = S_del_filename(self, seg_reader);
OutStream *outstream = Folder_Open_Out(folder, filename);
if (!outstream) { RETHROW(INCREF(Err_get_error())); }
@@ -246,7 +246,7 @@ DefDelWriter_Seg_Del_Count_IMP(DefaultDeletionsWriter *self,
BitVector *deldocs = tick
? (BitVector*)Vec_Fetch(ivars->bit_vecs, Int_Get_Value(tick))
: NULL;
- return deldocs ? BitVec_Count(deldocs) : 0;
+ return deldocs ? (int32_t)BitVec_Count(deldocs) : 0;
}
void
[3/7] lucy git commit: Factor out routine for octet size calculation.
Posted by ma...@apache.org.
Factor out routine for octet size calculation.
Create a dedicated static function which given a bit size returns a byte
size.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/efd6ac7b
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/efd6ac7b
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/efd6ac7b
Branch: refs/heads/master
Commit: efd6ac7bf73ffa4b99bfe493bb3ef1ef5c5e8ef6
Parents: 0728569
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 6 17:41:12 2016 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Apr 12 21:38:55 2016 -0700
----------------------------------------------------------------------
core/Lucy/Object/BitVector.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/efd6ac7b/core/Lucy/Object/BitVector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Object/BitVector.c b/core/Lucy/Object/BitVector.c
index b680553..6ae926f 100644
--- a/core/Lucy/Object/BitVector.c
+++ b/core/Lucy/Object/BitVector.c
@@ -46,6 +46,13 @@ static const uint32_t BYTE_COUNTS[256] = {
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
};
+static CFISH_INLINE size_t
+SI_octet_size(size_t bit_size) {
+ if (bit_size > SIZE_MAX - 8) {
+ return SIZE_MAX / 8;
+ }
+ return (bit_size + 7) / 8;
+}
BitVector*
BitVec_new(size_t capacity) {
@@ -56,7 +63,7 @@ BitVec_new(size_t capacity) {
BitVector*
BitVec_init(BitVector *self, size_t capacity) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
- const size_t byte_size = (capacity + 7) / 8;
+ const size_t byte_size = SI_octet_size(capacity);
// Derive.
ivars->bits = capacity
@@ -80,7 +87,7 @@ BitVector*
BitVec_Clone_IMP(BitVector *self) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
BitVector *other = BitVec_new(ivars->cap);
- size_t byte_size = (ivars->cap + 7) / 8;
+ size_t byte_size = SI_octet_size(ivars->cap);
BitVectorIVARS *const ovars = BitVec_IVARS(other);
// Forbid inheritance.
@@ -109,8 +116,8 @@ BitVec_Mimic_IMP(BitVector *self, Obj *other) {
CERTIFY(other, BITVECTOR);
BitVectorIVARS *const ivars = BitVec_IVARS(self);
BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
- const size_t my_byte_size = (ivars->cap + 7) / 8;
- const size_t other_byte_size = (ovars->cap + 7) / 8;
+ const size_t my_byte_size = SI_octet_size(ivars->cap);
+ const size_t other_byte_size = SI_octet_size(ovars->cap);
if (my_byte_size > other_byte_size) {
size_t space = my_byte_size - other_byte_size;
memset(ivars->bits + other_byte_size, 0, space);
@@ -125,8 +132,8 @@ void
BitVec_Grow_IMP(BitVector *self, size_t capacity) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
if (capacity > ivars->cap) {
- const size_t old_byte_cap = (ivars->cap + 7) / 8;
- const size_t new_byte_cap = (capacity + 7) / 8;
+ const size_t old_byte_cap = SI_octet_size(ivars->cap);
+ const size_t new_byte_cap = SI_octet_size(capacity);
const size_t num_new_bytes = new_byte_cap - old_byte_cap;
ivars->bits = (uint8_t*)REALLOCATE(ivars->bits, new_byte_cap);
@@ -157,7 +164,7 @@ BitVec_Clear_IMP(BitVector *self, size_t tick) {
void
BitVec_Clear_All_IMP(BitVector *self) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
- const size_t byte_size = (ivars->cap + 7) / 8;
+ const size_t byte_size = SI_octet_size(ivars->cap);
memset(ivars->bits, 0, byte_size);
}
@@ -182,7 +189,7 @@ S_first_bit_in_nonzero_byte(uint8_t num) {
int32_t
BitVec_Next_Hit_IMP(BitVector *self, size_t tick) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
- size_t byte_size = (ivars->cap + 7) / 8;
+ size_t byte_size = SI_octet_size(ivars->cap);
uint8_t *const limit = ivars->bits + byte_size;
uint8_t *ptr = ivars->bits + (tick >> 3);
@@ -222,7 +229,7 @@ BitVec_And_IMP(BitVector *self, const BitVector *other) {
const size_t min_cap = ivars->cap < ovars->cap
? ivars->cap
: ovars->cap;
- const size_t byte_size = (min_cap + 7) / 8;
+ const size_t byte_size = SI_octet_size(min_cap);
uint8_t *const limit = bits_a + byte_size;
// Intersection.
@@ -233,7 +240,7 @@ BitVec_And_IMP(BitVector *self, const BitVector *other) {
// Set all remaining to zero.
if (ivars->cap > min_cap) {
- const size_t self_byte_size = (ivars->cap + 7) / 8;
+ const size_t self_byte_size = SI_octet_size(ivars->cap);
memset(bits_a, 0, self_byte_size - byte_size);
}
}
@@ -271,7 +278,7 @@ S_do_or_or_xor(BitVector *self, const BitVector *other, int operation) {
if (max_cap > ivars->cap) { BitVec_Grow(self, max_cap); }
bits_a = ivars->bits;
bits_b = ovars->bits;
- byte_size = (min_cap + 7) / 8;
+ byte_size = SI_octet_size(min_cap);
limit = ivars->bits + (size_t)byte_size;
// Perform union of common bits.
@@ -293,7 +300,7 @@ S_do_or_or_xor(BitVector *self, const BitVector *other, int operation) {
// Copy remaining bits if other is bigger than self.
if (ovars->cap > min_cap) {
- const size_t other_byte_size = (ovars->cap + 7) / 8;
+ const size_t other_byte_size = SI_octet_size(ovars->cap);
const size_t bytes_to_copy = other_byte_size - byte_size;
memcpy(bits_a, bits_b, bytes_to_copy);
}
@@ -308,7 +315,7 @@ BitVec_And_Not_IMP(BitVector *self, const BitVector *other) {
const size_t min_cap = ivars->cap < ovars->cap
? ivars->cap
: ovars->cap;
- const size_t byte_size = (min_cap + 7) / 8;
+ const size_t byte_size = SI_octet_size(min_cap);
uint8_t *const limit = bits_a + byte_size;
// Clear bits set in other.
@@ -375,7 +382,7 @@ size_t
BitVec_Count_IMP(BitVector *self) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
size_t count = 0;
- const size_t byte_size = (ivars->cap + 7) / 8;
+ const size_t byte_size = SI_octet_size(ivars->cap);
uint8_t *ptr = ivars->bits;
uint8_t *const limit = ptr + byte_size;
@@ -393,7 +400,7 @@ BitVec_To_Array_IMP(BitVector *self) {
size_t num_left = count;
const size_t capacity = ivars->cap;
uint32_t *const array = (uint32_t*)CALLOCATE(count, sizeof(uint32_t));
- const size_t byte_size = (ivars->cap + 7) / 8;
+ const size_t byte_size = SI_octet_size(ivars->cap);
uint8_t *const bits = ivars->bits;
uint8_t *const limit = bits + byte_size;
uint32_t num = 0;
[4/7] lucy git commit: Change BitVector to use size_t indexes.
Posted by ma...@apache.org.
Change BitVector to use size_t indexes.
Have BitVector use a size_t to track its capacity and to index into the
bit array.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/07285699
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/07285699
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/07285699
Branch: refs/heads/master
Commit: 07285699c4f819d9be0dc1c7984c2bfe79be7851
Parents: 67c6fec
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 6 16:30:49 2016 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Apr 12 21:38:55 2016 -0700
----------------------------------------------------------------------
core/Lucy/Object/BitVector.c | 70 ++++++++++++++++++-------------------
core/Lucy/Object/BitVector.cfh | 24 ++++++-------
2 files changed, 47 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/07285699/core/Lucy/Object/BitVector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Object/BitVector.c b/core/Lucy/Object/BitVector.c
index d6406f2..b680553 100644
--- a/core/Lucy/Object/BitVector.c
+++ b/core/Lucy/Object/BitVector.c
@@ -48,15 +48,15 @@ static const uint32_t BYTE_COUNTS[256] = {
BitVector*
-BitVec_new(uint32_t capacity) {
+BitVec_new(size_t capacity) {
BitVector *self = (BitVector*)Class_Make_Obj(BITVECTOR);
return BitVec_init(self, capacity);
}
BitVector*
-BitVec_init(BitVector *self, uint32_t capacity) {
+BitVec_init(BitVector *self, size_t capacity) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
- const uint32_t byte_size = (capacity + 7) / 8;
+ const size_t byte_size = (capacity + 7) / 8;
// Derive.
ivars->bits = capacity
@@ -80,7 +80,7 @@ BitVector*
BitVec_Clone_IMP(BitVector *self) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
BitVector *other = BitVec_new(ivars->cap);
- uint32_t byte_size = (ivars->cap + 7) / 8;
+ size_t byte_size = (ivars->cap + 7) / 8;
BitVectorIVARS *const ovars = BitVec_IVARS(other);
// Forbid inheritance.
@@ -99,7 +99,7 @@ BitVec_Get_Raw_Bits_IMP(BitVector *self) {
return BitVec_IVARS(self)->bits;
}
-uint32_t
+size_t
BitVec_Get_Capacity_IMP(BitVector *self) {
return BitVec_IVARS(self)->cap;
}
@@ -109,10 +109,10 @@ BitVec_Mimic_IMP(BitVector *self, Obj *other) {
CERTIFY(other, BITVECTOR);
BitVectorIVARS *const ivars = BitVec_IVARS(self);
BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
- const uint32_t my_byte_size = (ivars->cap + 7) / 8;
- const uint32_t other_byte_size = (ovars->cap + 7) / 8;
+ const size_t my_byte_size = (ivars->cap + 7) / 8;
+ const size_t other_byte_size = (ovars->cap + 7) / 8;
if (my_byte_size > other_byte_size) {
- uint32_t space = my_byte_size - other_byte_size;
+ size_t space = my_byte_size - other_byte_size;
memset(ivars->bits + other_byte_size, 0, space);
}
else if (my_byte_size < other_byte_size) {
@@ -122,7 +122,7 @@ BitVec_Mimic_IMP(BitVector *self, Obj *other) {
}
void
-BitVec_Grow_IMP(BitVector *self, uint32_t capacity) {
+BitVec_Grow_IMP(BitVector *self, size_t capacity) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
if (capacity > ivars->cap) {
const size_t old_byte_cap = (ivars->cap + 7) / 8;
@@ -136,17 +136,17 @@ BitVec_Grow_IMP(BitVector *self, uint32_t capacity) {
}
void
-BitVec_Set_IMP(BitVector *self, uint32_t tick) {
+BitVec_Set_IMP(BitVector *self, size_t tick) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
if (tick >= ivars->cap) {
- uint32_t new_cap = (uint32_t)Memory_oversize(tick + 1, 0);
+ size_t new_cap = (size_t)Memory_oversize(tick + 1, 0);
BitVec_Grow(self, new_cap);
}
NumUtil_u1set(ivars->bits, tick);
}
void
-BitVec_Clear_IMP(BitVector *self, uint32_t tick) {
+BitVec_Clear_IMP(BitVector *self, size_t tick) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
if (tick >= ivars->cap) {
return;
@@ -162,7 +162,7 @@ BitVec_Clear_All_IMP(BitVector *self) {
}
bool
-BitVec_Get_IMP(BitVector *self, uint32_t tick) {
+BitVec_Get_IMP(BitVector *self, size_t tick) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
if (tick >= ivars->cap) {
return false;
@@ -180,7 +180,7 @@ S_first_bit_in_nonzero_byte(uint8_t num) {
}
int32_t
-BitVec_Next_Hit_IMP(BitVector *self, uint32_t tick) {
+BitVec_Next_Hit_IMP(BitVector *self, size_t tick) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
size_t byte_size = (ivars->cap + 7) / 8;
uint8_t *const limit = ivars->bits + byte_size;
@@ -219,9 +219,9 @@ BitVec_And_IMP(BitVector *self, const BitVector *other) {
const BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
uint8_t *bits_a = ivars->bits;
uint8_t *bits_b = ovars->bits;
- const uint32_t min_cap = ivars->cap < ovars->cap
- ? ivars->cap
- : ovars->cap;
+ const size_t min_cap = ivars->cap < ovars->cap
+ ? ivars->cap
+ : ovars->cap;
const size_t byte_size = (min_cap + 7) / 8;
uint8_t *const limit = bits_a + byte_size;
@@ -253,7 +253,7 @@ S_do_or_or_xor(BitVector *self, const BitVector *other, int operation) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
const BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
uint8_t *bits_a, *bits_b;
- uint32_t max_cap, min_cap;
+ size_t max_cap, min_cap;
uint8_t *limit;
double byte_size;
@@ -293,8 +293,8 @@ S_do_or_or_xor(BitVector *self, const BitVector *other, int operation) {
// Copy remaining bits if other is bigger than self.
if (ovars->cap > min_cap) {
- const double other_byte_size = (ovars->cap + 7) / 8;
- const size_t bytes_to_copy = (size_t)(other_byte_size - byte_size);
+ const size_t other_byte_size = (ovars->cap + 7) / 8;
+ const size_t bytes_to_copy = other_byte_size - byte_size;
memcpy(bits_a, bits_b, bytes_to_copy);
}
}
@@ -305,9 +305,9 @@ BitVec_And_Not_IMP(BitVector *self, const BitVector *other) {
const BitVectorIVARS *const ovars = BitVec_IVARS((BitVector*)other);
uint8_t *bits_a = ivars->bits;
uint8_t *bits_b = ovars->bits;
- const uint32_t min_cap = ivars->cap < ovars->cap
- ? ivars->cap
- : ovars->cap;
+ const size_t min_cap = ivars->cap < ovars->cap
+ ? ivars->cap
+ : ovars->cap;
const size_t byte_size = (min_cap + 7) / 8;
uint8_t *const limit = bits_a + byte_size;
@@ -319,20 +319,20 @@ BitVec_And_Not_IMP(BitVector *self, const BitVector *other) {
}
void
-BitVec_Flip_IMP(BitVector *self, uint32_t tick) {
+BitVec_Flip_IMP(BitVector *self, size_t tick) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
if (tick >= ivars->cap) {
- uint32_t new_cap = (uint32_t)Memory_oversize(tick + 1, 0);
+ size_t new_cap = Memory_oversize(tick + 1, 0);
BitVec_Grow(self, new_cap);
}
NumUtil_u1flip(ivars->bits, tick);
}
void
-BitVec_Flip_Block_IMP(BitVector *self, uint32_t offset, uint32_t length) {
+BitVec_Flip_Block_IMP(BitVector *self, size_t offset, size_t length) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
- uint32_t first = offset;
- uint32_t last = offset + length - 1;
+ size_t first = offset;
+ size_t last = offset + length - 1;
// Bail if there's nothing to flip.
if (!length) { return; }
@@ -356,8 +356,8 @@ BitVec_Flip_Block_IMP(BitVector *self, uint32_t offset, uint32_t length) {
}
// They must be multiples of 8, then.
else {
- const uint32_t start_tick = first >> 3;
- const uint32_t limit_tick = last >> 3;
+ const size_t start_tick = first >> 3;
+ const size_t limit_tick = last >> 3;
uint8_t *bits = ivars->bits + start_tick;
uint8_t *limit = ivars->bits + limit_tick;
@@ -371,10 +371,10 @@ BitVec_Flip_Block_IMP(BitVector *self, uint32_t offset, uint32_t length) {
}
}
-uint32_t
+size_t
BitVec_Count_IMP(BitVector *self) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
- uint32_t count = 0;
+ size_t count = 0;
const size_t byte_size = (ivars->cap + 7) / 8;
uint8_t *ptr = ivars->bits;
uint8_t *const limit = ptr + byte_size;
@@ -389,9 +389,9 @@ BitVec_Count_IMP(BitVector *self) {
I32Array*
BitVec_To_Array_IMP(BitVector *self) {
BitVectorIVARS *const ivars = BitVec_IVARS(self);
- uint32_t count = BitVec_Count(self);
- uint32_t num_left = count;
- const uint32_t capacity = ivars->cap;
+ size_t count = BitVec_Count(self);
+ size_t num_left = count;
+ const size_t capacity = ivars->cap;
uint32_t *const array = (uint32_t*)CALLOCATE(count, sizeof(uint32_t));
const size_t byte_size = (ivars->cap + 7) / 8;
uint8_t *const bits = ivars->bits;
http://git-wip-us.apache.org/repos/asf/lucy/blob/07285699/core/Lucy/Object/BitVector.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Object/BitVector.cfh b/core/Lucy/Object/BitVector.cfh
index adfb6cb..98a23d6 100644
--- a/core/Lucy/Object/BitVector.cfh
+++ b/core/Lucy/Object/BitVector.cfh
@@ -24,7 +24,7 @@ parcel Lucy;
public class Lucy::Object::BitVector nickname BitVec
inherits Clownfish::Obj {
- uint32_t cap;
+ size_t cap;
uint8_t *bits;
/** Create a new BitVector.
@@ -33,7 +33,7 @@ public class Lucy::Object::BitVector nickname BitVec
* able to hold.
*/
public inert incremented BitVector*
- new(uint32_t capacity = 0);
+ new(size_t capacity = 0);
/** Initialize a BitVector.
*
@@ -41,7 +41,7 @@ public class Lucy::Object::BitVector nickname BitVec
* able to hold.
*/
public inert BitVector*
- init(BitVector *self, uint32_t capacity = 0);
+ init(BitVector *self, size_t capacity = 0);
/** Return true if the bit at `tick` has been set, false if it
* hasn't (regardless of whether it lies within the bounds of the
@@ -50,14 +50,14 @@ public class Lucy::Object::BitVector nickname BitVec
* @param tick The requested bit.
*/
public bool
- Get(BitVector *self, uint32_t tick);
+ Get(BitVector *self, size_t tick);
/** Set the bit at `tick` to 1.
*
* @param tick The bit to be set.
*/
public void
- Set(BitVector *self, uint32_t tick);
+ Set(BitVector *self, size_t tick);
/** Accessor for the BitVector's underlying bit array.
*/
@@ -66,21 +66,21 @@ public class Lucy::Object::BitVector nickname BitVec
/** Accessor for capacity.
*/
- uint32_t
+ size_t
Get_Capacity(BitVector *self);
/** Returns the next set bit equal to or greater than `tick`,
* or -1 if no such bit exists.
*/
public int32_t
- Next_Hit(BitVector *self, uint32_t tick);
+ Next_Hit(BitVector *self, size_t tick);
/** Clear the indicated bit. (i.e. set it to 0).
*
* @param tick The bit to be cleared.
*/
public void
- Clear(BitVector *self, uint32_t tick);
+ Clear(BitVector *self, size_t tick);
/** Clear all bits.
*/
@@ -93,7 +93,7 @@ public class Lucy::Object::BitVector nickname BitVec
* @param capacity Least number of bits the BitVector should accomodate.
*/
public void
- Grow(BitVector *self, uint32_t capacity);
+ Grow(BitVector *self, size_t capacity);
/** Modify the contents of this BitVector so that it has the same bits set
* as `other`.
@@ -139,7 +139,7 @@ public class Lucy::Object::BitVector nickname BitVec
* @param tick The bit to invert.
*/
public void
- Flip(BitVector *self, uint32_t tick);
+ Flip(BitVector *self, size_t tick);
/** Invert each bit within a contiguous block.
*
@@ -147,11 +147,11 @@ public class Lucy::Object::BitVector nickname BitVec
* @param length The number of bits to flip.
*/
public void
- Flip_Block(BitVector *self, uint32_t offset, uint32_t length);
+ Flip_Block(BitVector *self, size_t offset, size_t length);
/** Return a count of the number of set bits.
*/
- public uint32_t
+ public size_t
Count(BitVector *self);
/** Return an array where each element represents a set bit.
[6/7] lucy git commit: Rework BitVector tests for index width change.
Posted by ma...@apache.org.
Rework BitVector tests for index width change.
Changing indexes from uint32_t to size_t requires updating a fair amount
of test code.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e03b8c71
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e03b8c71
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e03b8c71
Branch: refs/heads/master
Commit: e03b8c7160bca49bb212bdf027a7f9ca2d2c4524
Parents: 0a6ea88
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 6 17:56:36 2016 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Apr 12 21:38:55 2016 -0700
----------------------------------------------------------------------
core/Lucy/Test/Object/TestBitVector.c | 169 +++++++++++++----------------
1 file changed, 78 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/e03b8c71/core/Lucy/Test/Object/TestBitVector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Object/TestBitVector.c b/core/Lucy/Test/Object/TestBitVector.c
index c8c4203..d6080b7 100644
--- a/core/Lucy/Test/Object/TestBitVector.c
+++ b/core/Lucy/Test/Object/TestBitVector.c
@@ -33,10 +33,9 @@ TestBitVector_new() {
static void
test_Set_and_Get(TestBatchRunner *runner) {
- unsigned i, max;
- const uint32_t three = 3;
- const uint32_t seventeen = 17;
- BitVector *bit_vec = BitVec_new(8);
+ const size_t three = 3;
+ const size_t seventeen = 17;
+ BitVector *bit_vec = BitVec_new(8);
BitVec_Set(bit_vec, three);
TEST_TRUE(runner, BitVec_Get_Capacity(bit_vec) < seventeen,
@@ -45,12 +44,13 @@ test_Set_and_Get(TestBatchRunner *runner) {
TEST_TRUE(runner, BitVec_Get_Capacity(bit_vec) > seventeen,
"set above cap causes BitVector to grow");
+ size_t i, max;
for (i = 0, max = BitVec_Get_Capacity(bit_vec); i < max; i++) {
if (i == three || i == seventeen) {
- TEST_TRUE(runner, BitVec_Get(bit_vec, i), "set/get %d", i);
+ TEST_TRUE(runner, BitVec_Get(bit_vec, i), "set/get %u", (unsigned)i);
}
else {
- TEST_FALSE(runner, BitVec_Get(bit_vec, i), "get %d", i);
+ TEST_FALSE(runner, BitVec_Get(bit_vec, i), "get %u", (unsigned)i);
}
}
TEST_FALSE(runner, BitVec_Get(bit_vec, i), "out of range get");
@@ -61,18 +61,18 @@ test_Set_and_Get(TestBatchRunner *runner) {
static void
test_Flip(TestBatchRunner *runner) {
BitVector *bit_vec = BitVec_new(0);
- int i;
+ unsigned i;
for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); }
for (i = 0; i <= 20; i++) {
- TEST_TRUE(runner, BitVec_Get(bit_vec, i), "flip on %d", i);
+ TEST_TRUE(runner, BitVec_Get(bit_vec, i), "flip on %u", i);
}
- TEST_FALSE(runner, BitVec_Get(bit_vec, i), "no flip %d", i);
+ TEST_FALSE(runner, BitVec_Get(bit_vec, i), "no flip %u", i);
for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); }
for (i = 0; i <= 20; i++) {
- TEST_FALSE(runner, BitVec_Get(bit_vec, i), "flip off %d", i);
+ TEST_FALSE(runner, BitVec_Get(bit_vec, i), "flip off %u", i);
}
- TEST_FALSE(runner, BitVec_Get(bit_vec, i), "still no flip %d", i);
+ TEST_FALSE(runner, BitVec_Get(bit_vec, 21), "still no flip %u", i);
DECREF(bit_vec);
}
@@ -80,20 +80,19 @@ test_Flip(TestBatchRunner *runner) {
static void
test_Flip_Block_ascending(TestBatchRunner *runner) {
BitVector *bit_vec = BitVec_new(0);
- int i;
- for (i = 0; i <= 20; i++) {
+ for (unsigned i = 0; i <= 20; i++) {
BitVec_Flip_Block(bit_vec, i, 21 - i);
}
- for (i = 0; i <= 20; i++) {
+ for (unsigned i = 0; i <= 20; i++) {
if (i % 2 == 0) {
TEST_TRUE(runner, BitVec_Get(bit_vec, i),
- "Flip_Block ascending %d", i);
+ "Flip_Block ascending %u", i);
}
else {
TEST_FALSE(runner, BitVec_Get(bit_vec, i),
- "Flip_Block ascending %d", i);
+ "Flip_Block ascending %u", i);
}
}
@@ -103,20 +102,19 @@ test_Flip_Block_ascending(TestBatchRunner *runner) {
static void
test_Flip_Block_descending(TestBatchRunner *runner) {
BitVector *bit_vec = BitVec_new(0);
- int i;
- for (i = 19; i >= 0; i--) {
- BitVec_Flip_Block(bit_vec, 1, i);
+ for (int i = 19; i >= 0; i--) {
+ BitVec_Flip_Block(bit_vec, 1, (size_t)i);
}
- for (i = 0; i <= 20; i++) {
+ for (unsigned i = 0; i <= 20; i++) {
if (i % 2) {
TEST_TRUE(runner, BitVec_Get(bit_vec, i),
- "Flip_Block descending %d", i);
+ "Flip_Block descending %u", i);
}
else {
TEST_FALSE(runner, BitVec_Get(bit_vec, i),
- "Flip_Block descending %d", i);
+ "Flip_Block descending %u", i);
}
}
@@ -125,25 +123,22 @@ test_Flip_Block_descending(TestBatchRunner *runner) {
static void
test_Flip_Block_bulk(TestBatchRunner *runner) {
- int32_t offset;
-
- for (offset = 0; offset <= 17; offset++) {
- int32_t len;
- for (len = 0; len <= 17; len++) {
- int i;
- int upper = offset + len - 1;
+ for (unsigned offset = 0; offset <= 17; offset++) {
+ for (unsigned len = 0; len <= 17; len++) {
+ int upper = (int)offset + (int)len - 1;
BitVector *bit_vec = BitVec_new(0);
BitVec_Flip_Block(bit_vec, offset, len);
+ unsigned i;
for (i = 0; i <= 17; i++) {
- if (i >= offset && i <= upper) {
+ if (i >= offset && (int)i <= upper) {
if (!BitVec_Get(bit_vec, i)) { break; }
}
else {
if (BitVec_Get(bit_vec, i)) { break; }
}
}
- TEST_INT_EQ(runner, i, 18, "Flip_Block(%d, %d)", offset, len);
+ TEST_UINT_EQ(runner, i, 18, "Flip_Block(%u, %u)", offset, len);
DECREF(bit_vec);
}
@@ -152,12 +147,8 @@ test_Flip_Block_bulk(TestBatchRunner *runner) {
static void
test_Mimic(TestBatchRunner *runner) {
- int foo;
-
- for (foo = 0; foo <= 17; foo++) {
- int bar;
- for (bar = 0; bar <= 17; bar++) {
- int i;
+ for (unsigned foo = 0; foo <= 17; foo++) {
+ for (unsigned bar = 0; bar <= 17; bar++) {
BitVector *foo_vec = BitVec_new(0);
BitVector *bar_vec = BitVec_new(0);
@@ -165,10 +156,11 @@ test_Mimic(TestBatchRunner *runner) {
BitVec_Set(bar_vec, bar);
BitVec_Mimic(foo_vec, (Obj*)bar_vec);
+ unsigned i;
for (i = 0; i <= 17; i++) {
if (BitVec_Get(foo_vec, i) && i != bar) { break; }
}
- TEST_INT_EQ(runner, i, 18, "Mimic(%d, %d)", foo, bar);
+ TEST_UINT_EQ(runner, i, 18, "Mimic(%u, %u)", foo, bar);
DECREF(foo_vec);
DECREF(bar_vec);
@@ -178,14 +170,13 @@ test_Mimic(TestBatchRunner *runner) {
static BitVector*
S_create_set(int set_num) {
- int i;
- int nums_1[] = { 1, 2, 3, 10, 20, 30, 0 };
- int nums_2[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ unsigned nums_1[] = { 1, 2, 3, 10, 20, 30, 0 };
+ unsigned nums_2[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 0
};
- int *nums = set_num == 1 ? nums_1 : nums_2;
+ unsigned *nums = set_num == 1 ? nums_1 : nums_2;
BitVector *bit_vec = BitVec_new(31);
- for (i = 0; nums[i] != 0; i++) {
+ for (unsigned i = 0; nums[i] != 0; i++) {
BitVec_Set(bit_vec, nums[i]);
}
return bit_vec;
@@ -195,10 +186,10 @@ S_create_set(int set_num) {
#define OP_XOR 2
#define OP_AND 3
#define OP_AND_NOT 4
-static int
+static unsigned
S_verify_logical_op(BitVector *bit_vec, BitVector *set_1, BitVector *set_2,
int op) {
- int i;
+ unsigned i;
for (i = 0; i < 50; i++) {
bool wanted;
@@ -235,11 +226,11 @@ test_Or(TestBatchRunner *runner) {
BitVector *set_2 = S_create_set(2);
BitVec_Or(smaller, set_2);
- TEST_INT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_OR),
- 50, "OR with self smaller than other");
+ TEST_UINT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_OR),
+ 50, "OR with self smaller than other");
BitVec_Or(larger, set_1);
- TEST_INT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_OR),
- 50, "OR with other smaller than self");
+ TEST_UINT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_OR),
+ 50, "OR with other smaller than self");
DECREF(smaller);
DECREF(larger);
@@ -255,11 +246,11 @@ test_Xor(TestBatchRunner *runner) {
BitVector *set_2 = S_create_set(2);
BitVec_Xor(smaller, set_2);
- TEST_INT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_XOR),
- 50, "XOR with self smaller than other");
+ TEST_UINT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_XOR),
+ 50, "XOR with self smaller than other");
BitVec_Xor(larger, set_1);
- TEST_INT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_XOR),
- 50, "XOR with other smaller than self");
+ TEST_UINT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_XOR),
+ 50, "XOR with other smaller than self");
DECREF(smaller);
DECREF(larger);
@@ -275,11 +266,11 @@ test_And(TestBatchRunner *runner) {
BitVector *set_2 = S_create_set(2);
BitVec_And(smaller, set_2);
- TEST_INT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_AND),
- 50, "AND with self smaller than other");
+ TEST_UINT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_AND),
+ 50, "AND with self smaller than other");
BitVec_And(larger, set_1);
- TEST_INT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_AND),
- 50, "AND with other smaller than self");
+ TEST_UINT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_AND),
+ 50, "AND with other smaller than self");
DECREF(smaller);
DECREF(larger);
@@ -295,13 +286,13 @@ test_And_Not(TestBatchRunner *runner) {
BitVector *set_2 = S_create_set(2);
BitVec_And_Not(smaller, set_2);
- TEST_INT_EQ(runner,
- S_verify_logical_op(smaller, set_1, set_2, OP_AND_NOT),
- 50, "AND_NOT with self smaller than other");
+ TEST_UINT_EQ(runner,
+ S_verify_logical_op(smaller, set_1, set_2, OP_AND_NOT),
+ 50, "AND_NOT with self smaller than other");
BitVec_And_Not(larger, set_1);
- TEST_INT_EQ(runner,
- S_verify_logical_op(larger, set_2, set_1, OP_AND_NOT),
- 50, "AND_NOT with other smaller than self");
+ TEST_UINT_EQ(runner,
+ S_verify_logical_op(larger, set_2, set_1, OP_AND_NOT),
+ 50, "AND_NOT with other smaller than self");
DECREF(smaller);
DECREF(larger);
@@ -311,44 +302,41 @@ test_And_Not(TestBatchRunner *runner) {
static void
test_Count(TestBatchRunner *runner) {
- int i;
- int shuffled[64];
+ unsigned shuffled[64];
BitVector *bit_vec = BitVec_new(64);
- for (i = 0; i < 64; i++) { shuffled[i] = i; }
- for (i = 0; i < 64; i++) {
- int shuffle_pos = rand() % 64;
- int temp = shuffled[shuffle_pos];
+ for (unsigned i = 0; i < 64; i++) { shuffled[i] = i; }
+ for (unsigned i = 0; i < 64; i++) {
+ unsigned shuffle_pos = (unsigned)rand() % 64;
+ unsigned temp = shuffled[shuffle_pos];
shuffled[shuffle_pos] = shuffled[i];
shuffled[i] = temp;
}
+ unsigned i;
for (i = 0; i < 64; i++) {
BitVec_Set(bit_vec, shuffled[i]);
if (BitVec_Count(bit_vec) != (uint32_t)(i + 1)) { break; }
}
- TEST_INT_EQ(runner, i, 64, "Count() returns the right number of bits");
+ TEST_UINT_EQ(runner, i, 64, "Count() returns the right number of bits");
DECREF(bit_vec);
}
static void
test_Next_Hit(TestBatchRunner *runner) {
- int i;
-
- for (i = 24; i <= 33; i++) {
- int probe;
+ for (int i = 24; i <= 33; i++) {
BitVector *bit_vec = BitVec_new(64);
- BitVec_Set(bit_vec, i);
+ BitVec_Set(bit_vec, (size_t)i);
TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, 0), i,
"Next_Hit for 0 is %d", i);
TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, 0), i,
"Next_Hit for 1 is %d", i);
- for (probe = 15; probe <= i; probe++) {
- TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, probe), i,
+ for (int probe = 15; probe <= i; probe++) {
+ TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, (size_t)probe), i,
"Next_Hit for %d is %d", probe, i);
}
- for (probe = i + 1; probe <= i + 9; probe++) {
- TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, probe), -1,
+ for (int probe = i + 1; probe <= i + 9; probe++) {
+ TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, (size_t)probe), -1,
"no Next_Hit for %d when max is %d", probe, i);
}
DECREF(bit_vec);
@@ -366,7 +354,6 @@ test_Clear_All(TestBatchRunner *runner) {
static void
test_Clone(TestBatchRunner *runner) {
- int i;
BitVector *self = BitVec_new(30);
BitVector *twin;
@@ -376,11 +363,12 @@ test_Clone(TestBatchRunner *runner) {
BitVec_Set(self, 20);
twin = BitVec_Clone(self);
+ size_t i;
for (i = 0; i < 50; i++) {
if (BitVec_Get(self, i) != BitVec_Get(twin, i)) { break; }
}
- TEST_INT_EQ(runner, i, 50, "Clone");
- TEST_INT_EQ(runner, BitVec_Count(twin), 4, "clone Count");
+ TEST_UINT_EQ(runner, i, 50, "Clone");
+ TEST_UINT_EQ(runner, BitVec_Count(twin), 4, "clone Count");
DECREF(self);
DECREF(twin);
@@ -398,12 +386,11 @@ test_To_Array(TestBatchRunner *runner) {
uint64_t *source_ints = TestUtils_random_u64s(NULL, 20, 0, 200);
BitVector *bit_vec = BitVec_new(0);
I32Array *array;
- long num_unique = 0;
- long i;
+ unsigned num_unique = 0;
// Unique the random ints.
qsort(source_ints, 20, sizeof(uint64_t), S_compare_u64s);
- for (i = 0; i < 19; i++) {
+ for (unsigned i = 0; i < 19; i++) {
if (source_ints[i] != source_ints[i + 1]) {
source_ints[num_unique] = source_ints[i];
num_unique++;
@@ -411,17 +398,18 @@ test_To_Array(TestBatchRunner *runner) {
}
// Set bits.
- for (i = 0; i < num_unique; i++) {
- BitVec_Set(bit_vec, (uint32_t)source_ints[i]);
+ for (unsigned i = 0; i < num_unique; i++) {
+ BitVec_Set(bit_vec, (size_t)source_ints[i]);
}
// Create the array and compare it to the source.
array = BitVec_To_Array(bit_vec);
+ unsigned i;
for (i = 0; i < num_unique; i++) {
if (I32Arr_Get(array, (size_t)i) != (int32_t)source_ints[i]) { break; }
}
- TEST_INT_EQ(runner, i, num_unique, "To_Array (%ld == %ld)", i,
- num_unique);
+ TEST_UINT_EQ(runner, i, num_unique, "To_Array (%u == %u)", i,
+ num_unique);
DECREF(array);
DECREF(bit_vec);
@@ -432,8 +420,7 @@ test_To_Array(TestBatchRunner *runner) {
// Valgrind only - detect off-by-one error.
static void
test_off_by_one_error() {
- int cap;
- for (cap = 5; cap <= 24; cap++) {
+ for (unsigned cap = 5; cap <= 24; cap++) {
BitVector *bit_vec = BitVec_new(cap);
BitVec_Set(bit_vec, cap - 2);
DECREF(bit_vec);
[5/7] lucy git commit: Widen arguments to BitVector functions.
Posted by ma...@apache.org.
Widen arguments to BitVector functions.
BitVector API functions now take size_t indexes rather than uint32_t.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/0a6ea88d
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/0a6ea88d
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/0a6ea88d
Branch: refs/heads/master
Commit: 0a6ea88df1e5064609561e874b74707c855097b2
Parents: efd6ac7
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 6 17:51:01 2016 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Apr 12 21:38:55 2016 -0700
----------------------------------------------------------------------
core/Lucy/Index/DeletionsWriter.c | 16 ++++++++--------
core/Lucy/Search/BitVecMatcher.c | 5 +++--
core/Lucy/Search/Collector.c | 2 +-
core/Lucy/Search/PhraseQuery.c | 4 ++--
core/Lucy/Test/Search/TestSeriesMatcher.c | 4 ++--
core/LucyX/Search/FilterMatcher.c | 2 +-
core/LucyX/Search/ProximityQuery.c | 4 ++--
7 files changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/0a6ea88d/core/Lucy/Index/DeletionsWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/DeletionsWriter.c b/core/Lucy/Index/DeletionsWriter.c
index c646658..adf0d53 100644
--- a/core/Lucy/Index/DeletionsWriter.c
+++ b/core/Lucy/Index/DeletionsWriter.c
@@ -98,7 +98,7 @@ DefDelWriter_init(DefaultDeletionsWriter *self, Schema *schema,
// Materialize a BitVector of deletions for each segment.
for (size_t i = 0; i < num_seg_readers; i++) {
SegReader *seg_reader = (SegReader*)Vec_Fetch(ivars->seg_readers, i);
- BitVector *bit_vec = BitVec_new(SegReader_Doc_Max(seg_reader));
+ BitVector *bit_vec = BitVec_new((size_t)SegReader_Doc_Max(seg_reader));
DeletionsReader *del_reader
= (DeletionsReader*)SegReader_Fetch(
seg_reader, Class_Get_Name(DELETIONSREADER));
@@ -109,7 +109,7 @@ DefDelWriter_init(DefaultDeletionsWriter *self, Schema *schema,
if (seg_dels) {
int32_t del;
while (0 != (del = Matcher_Next(seg_dels))) {
- BitVec_Set(bit_vec, del);
+ BitVec_Set(bit_vec, (size_t)del);
}
DECREF(seg_dels);
}
@@ -268,8 +268,8 @@ DefDelWriter_Delete_By_Term_IMP(DefaultDeletionsWriter *self,
// Iterate through postings, marking each doc as deleted.
if (plist) {
while (0 != (doc_id = PList_Next(plist))) {
- num_zapped += !BitVec_Get(bit_vec, doc_id);
- BitVec_Set(bit_vec, doc_id);
+ num_zapped += !BitVec_Get(bit_vec, (size_t)doc_id);
+ BitVec_Set(bit_vec, (size_t)doc_id);
}
if (num_zapped) { ivars->updated[i] = true; }
DECREF(plist);
@@ -294,8 +294,8 @@ DefDelWriter_Delete_By_Query_IMP(DefaultDeletionsWriter *self, Query *query) {
// Iterate through matches, marking each doc as deleted.
while (0 != (doc_id = Matcher_Next(matcher))) {
- num_zapped += !BitVec_Get(bit_vec, doc_id);
- BitVec_Set(bit_vec, doc_id);
+ num_zapped += !BitVec_Get(bit_vec, (size_t)doc_id);
+ BitVec_Set(bit_vec, (size_t)doc_id);
}
if (num_zapped) { ivars->updated[i] = true; }
@@ -314,9 +314,9 @@ DefDelWriter_Delete_By_Doc_ID_IMP(DefaultDeletionsWriter *self, int32_t doc_id)
int32_t offset = I32Arr_Get(ivars->seg_starts, sub_tick);
int32_t seg_doc_id = doc_id - offset;
- if (!BitVec_Get(bit_vec, seg_doc_id)) {
+ if (!BitVec_Get(bit_vec, (size_t)seg_doc_id)) {
ivars->updated[sub_tick] = true;
- BitVec_Set(bit_vec, seg_doc_id);
+ BitVec_Set(bit_vec, (size_t)seg_doc_id);
}
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/0a6ea88d/core/Lucy/Search/BitVecMatcher.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/BitVecMatcher.c b/core/Lucy/Search/BitVecMatcher.c
index 7ca5c0a..502f0fd 100644
--- a/core/Lucy/Search/BitVecMatcher.c
+++ b/core/Lucy/Search/BitVecMatcher.c
@@ -44,14 +44,15 @@ BitVecMatcher_Destroy_IMP(BitVecMatcher *self) {
int32_t
BitVecMatcher_Next_IMP(BitVecMatcher *self) {
BitVecMatcherIVARS *const ivars = BitVecMatcher_IVARS(self);
- ivars->doc_id = BitVec_Next_Hit(ivars->bit_vec, ivars->doc_id + 1);
+ ivars->doc_id
+ = BitVec_Next_Hit(ivars->bit_vec, (size_t)(ivars->doc_id + 1));
return ivars->doc_id == -1 ? 0 : ivars->doc_id;
}
int32_t
BitVecMatcher_Advance_IMP(BitVecMatcher *self, int32_t target) {
BitVecMatcherIVARS *const ivars = BitVecMatcher_IVARS(self);
- ivars->doc_id = BitVec_Next_Hit(ivars->bit_vec, target);
+ ivars->doc_id = BitVec_Next_Hit(ivars->bit_vec, (size_t)target);
return ivars->doc_id == -1 ? 0 : ivars->doc_id;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/0a6ea88d/core/Lucy/Search/Collector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/Collector.c b/core/Lucy/Search/Collector.c
index 6564018..f9ef3ba 100644
--- a/core/Lucy/Search/Collector.c
+++ b/core/Lucy/Search/Collector.c
@@ -88,7 +88,7 @@ BitColl_Collect_IMP(BitCollector *self, int32_t doc_id) {
BitCollectorIVARS *const ivars = BitColl_IVARS(self);
// Add the doc_id to the BitVector.
- BitVec_Set(ivars->bit_vec, (ivars->base + doc_id));
+ BitVec_Set(ivars->bit_vec, (size_t)(ivars->base + doc_id));
}
bool
http://git-wip-us.apache.org/repos/asf/lucy/blob/0a6ea88d/core/Lucy/Search/PhraseQuery.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/PhraseQuery.c b/core/Lucy/Search/PhraseQuery.c
index 48d7c13..9d2f277 100644
--- a/core/Lucy/Search/PhraseQuery.c
+++ b/core/Lucy/Search/PhraseQuery.c
@@ -376,7 +376,7 @@ PhraseCompiler_Highlight_Spans_IMP(PhraseCompiler *self, Searcher *searcher,
// Set initial positions from first term.
I32Array *positions = TV_Get_Positions(term_vector);
for (size_t j = I32Arr_Get_Size(positions); j > 0; j--) {
- BitVec_Set(posit_vec, (uint32_t)I32Arr_Get(positions, j - 1));
+ BitVec_Set(posit_vec, (size_t)I32Arr_Get(positions, j - 1));
}
}
else {
@@ -387,7 +387,7 @@ PhraseCompiler_Highlight_Spans_IMP(PhraseCompiler *self, Searcher *searcher,
for (size_t j = I32Arr_Get_Size(positions); j > 0; j--) {
int32_t pos = I32Arr_Get(positions, j - 1) - (int32_t)i;
if (pos >= 0) {
- BitVec_Set(other_posit_vec, pos);
+ BitVec_Set(other_posit_vec, (size_t)pos);
}
}
BitVec_And(posit_vec, other_posit_vec);
http://git-wip-us.apache.org/repos/asf/lucy/blob/0a6ea88d/core/Lucy/Test/Search/TestSeriesMatcher.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestSeriesMatcher.c b/core/Lucy/Test/Search/TestSeriesMatcher.c
index d0ec08e..0fd0ae6 100644
--- a/core/Lucy/Test/Search/TestSeriesMatcher.c
+++ b/core/Lucy/Test/Search/TestSeriesMatcher.c
@@ -42,12 +42,12 @@ S_make_series_matcher(I32Array *doc_ids, I32Array *offsets, int32_t doc_max) {
int32_t max = i == num_matchers - 1
? doc_max + 1
: I32Arr_Get(offsets, i + 1);
- BitVector *bit_vec = BitVec_new(max - offset);
+ BitVector *bit_vec = BitVec_new((size_t)(max - offset));
while (tick < num_doc_ids) {
int32_t doc_id = I32Arr_Get(doc_ids, tick);
if (doc_id > max) { break; }
else { tick++; }
- BitVec_Set(bit_vec, doc_id - offset);
+ BitVec_Set(bit_vec, (size_t)(doc_id - offset));
}
Vec_Push(matchers, (Obj*)BitVecMatcher_new(bit_vec));
DECREF(bit_vec);
http://git-wip-us.apache.org/repos/asf/lucy/blob/0a6ea88d/core/LucyX/Search/FilterMatcher.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/FilterMatcher.c b/core/LucyX/Search/FilterMatcher.c
index c187ee0..86fdb66 100644
--- a/core/LucyX/Search/FilterMatcher.c
+++ b/core/LucyX/Search/FilterMatcher.c
@@ -55,7 +55,7 @@ FilterMatcher_Next_IMP(FilterMatcher* self) {
ivars->doc_id--;
return 0;
}
- } while (!BitVec_Get(ivars->bits, ivars->doc_id));
+ } while (!BitVec_Get(ivars->bits, (size_t)ivars->doc_id));
return ivars->doc_id;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/0a6ea88d/core/LucyX/Search/ProximityQuery.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/ProximityQuery.c b/core/LucyX/Search/ProximityQuery.c
index 2f31933..6b01d5b 100644
--- a/core/LucyX/Search/ProximityQuery.c
+++ b/core/LucyX/Search/ProximityQuery.c
@@ -405,7 +405,7 @@ ProximityCompiler_Highlight_Spans_IMP(ProximityCompiler *self,
// Set initial positions from first term.
I32Array *positions = TV_Get_Positions(term_vector);
for (size_t j = I32Arr_Get_Size(positions); j > 0; j--) {
- BitVec_Set(posit_vec, (uint32_t)I32Arr_Get(positions, j - 1));
+ BitVec_Set(posit_vec, (size_t)I32Arr_Get(positions, j - 1));
}
}
else {
@@ -416,7 +416,7 @@ ProximityCompiler_Highlight_Spans_IMP(ProximityCompiler *self,
for (size_t j = I32Arr_Get_Size(positions); j > 0; j--) {
int32_t pos = I32Arr_Get(positions, j - 1) - (int32_t)i;
if (pos >= 0) {
- BitVec_Set(other_posit_vec, pos);
+ BitVec_Set(other_posit_vec, (size_t)pos);
}
}
BitVec_And(posit_vec, other_posit_vec);
[7/7] lucy git commit: Merge branch 'LUCY-295-bitvec-size'
Posted by ma...@apache.org.
Merge branch 'LUCY-295-bitvec-size'
Change BitVector to use `size_t` instead of `uint32_t` to address
bits in the array.
This fixes #40.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/54841aa7
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/54841aa7
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/54841aa7
Branch: refs/heads/master
Commit: 54841aa79335c214c7217b053bb42162752358bb
Parents: 67c6fec 42640a6
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Apr 13 16:05:24 2016 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Apr 13 16:05:24 2016 -0700
----------------------------------------------------------------------
core/Lucy/Index/BitVecDelDocs.c | 4 +-
core/Lucy/Index/DeletionsWriter.c | 22 ++--
core/Lucy/Object/BitVector.c | 97 +++++++-------
core/Lucy/Object/BitVector.cfh | 24 ++--
core/Lucy/Search/BitVecMatcher.c | 5 +-
core/Lucy/Search/Collector.c | 2 +-
core/Lucy/Search/PhraseQuery.c | 4 +-
core/Lucy/Test/Object/TestBitVector.c | 169 ++++++++++++-------------
core/Lucy/Test/Search/TestSeriesMatcher.c | 4 +-
core/LucyX/Search/FilterMatcher.c | 2 +-
core/LucyX/Search/ProximityQuery.c | 4 +-
go/lucy/object.go | 4 +-
12 files changed, 168 insertions(+), 173 deletions(-)
----------------------------------------------------------------------