Repository: lucy Updated Branches: refs/heads/master 8b4ad2105 -> e6b61338c
Duplicate IO C32 as explicitly unsigned CU32. Prepare for the addition of CI32 -- a signed compressed integer. Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/8a48ef58 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/8a48ef58 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/8a48ef58 Branch: refs/heads/master Commit: 8a48ef58e2592336594bebb08a25ea763f83037c Parents: 4370756 Author: Marvin Humphrey <mar...@rectangular.com> Authored: Mon Apr 18 12:32:54 2016 -0700 Committer: Marvin Humphrey <mar...@rectangular.com> Committed: Mon Apr 18 15:12:09 2016 -0700 ---------------------------------------------------------------------- core/Lucy/Store/InStream.c | 26 ++++++++++++++++++++++++ core/Lucy/Store/InStream.cfh | 17 +++++++++++++--- core/Lucy/Store/OutStream.c | 30 ++++++++++++++++++++++------ core/Lucy/Store/OutStream.cfh | 10 ++++++++++ core/Lucy/Test/Store/TestIOPrimitives.c | 26 ++++++++++++------------ 5 files changed, 87 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/8a48ef58/core/Lucy/Store/InStream.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Store/InStream.c b/core/Lucy/Store/InStream.c index a6d61d8..09da76f 100644 --- a/core/Lucy/Store/InStream.c +++ b/core/Lucy/Store/InStream.c @@ -49,6 +49,12 @@ S_fill(InStream *self, int64_t amount); static int64_t S_refill(InStream *self); +static CFISH_INLINE uint32_t +SI_read_cu32(InStream *self); + +static CFISH_INLINE uint64_t +SI_read_cu64(InStream *self); + InStream* InStream_open(Obj *file) { InStream *self = (InStream*)Class_Make_Obj(INSTREAM); @@ -468,6 +474,16 @@ InStream_Read_F64_IMP(InStream *self) { uint32_t InStream_Read_C32_IMP(InStream *self) { + return SI_read_cu32(self); +} + +uint32_t +InStream_Read_CU32_IMP(InStream *self) { + return SI_read_cu32(self); +} + +static CFISH_INLINE uint32_t +SI_read_cu32(InStream *self) { InStreamIVARS *const ivars = InStream_IVARS(self); uint32_t retval = 0; while (1) { @@ -482,6 +498,16 @@ InStream_Read_C32_IMP(InStream *self) { uint64_t InStream_Read_C64_IMP(InStream *self) { + return SI_read_cu64(self); +} + +uint64_t +InStream_Read_CU64_IMP(InStream *self) { + return SI_read_cu64(self); +} + +static CFISH_INLINE uint64_t +SI_read_cu64(InStream *self) { InStreamIVARS *const ivars = InStream_IVARS(self); uint64_t retval = 0; while (1) { http://git-wip-us.apache.org/repos/asf/lucy/blob/8a48ef58/core/Lucy/Store/InStream.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Store/InStream.cfh b/core/Lucy/Store/InStream.cfh index efa7f63..5fd5dab 100644 --- a/core/Lucy/Store/InStream.cfh +++ b/core/Lucy/Store/InStream.cfh @@ -176,15 +176,26 @@ class Lucy::Store::InStream inherits Clownfish::Obj { uint32_t Read_C32(InStream *self); + /** Read in a compressed 32-bit unsigned integer. + */ + uint32_t + Read_CU32(InStream *self); + /** Read a 64-bit integer, using the same encoding as a C32 but occupying * as many as 10 bytes. */ final uint64_t Read_C64(InStream *self); - /** Read the bytes for a C32/C64 into `buf`. Return the number - * of bytes read. The caller must ensure that sufficient space exists in - * `buf` (worst case is 10 bytes). + /** Read a 64-bit unsigned integer, using the same encoding as a CU32 but + * occupying as many as 10 bytes. + */ + final uint64_t + Read_CU64(InStream *self); + + /** Read the bytes for a compressed 64-bit integer into `buf`. Return the + * number of bytes read. The caller must ensure that sufficient space + * exists in `buf` (worst case is 10 bytes). */ final int Read_Raw_C64(InStream *self, char *buf); http://git-wip-us.apache.org/repos/asf/lucy/blob/8a48ef58/core/Lucy/Store/OutStream.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Store/OutStream.c b/core/Lucy/Store/OutStream.c index d0fadd4..8839791 100644 --- a/core/Lucy/Store/OutStream.c +++ b/core/Lucy/Store/OutStream.c @@ -33,9 +33,13 @@ static CFISH_INLINE void SI_write_bytes(OutStream *self, OutStreamIVARS *ivars, const void *bytes, size_t len); -// Inlined version of OutStream_Write_C32. +// Inlined version of OutStream_Write_CU32. static CFISH_INLINE void -SI_write_c32(OutStream *self, OutStreamIVARS *ivars, uint32_t value); +SI_write_cu32(OutStream *self, OutStreamIVARS *ivars, uint32_t value); + +// Inlined version of OutStream_Write_CU64. +static CFISH_INLINE void +SI_write_cu64(OutStream *self, OutStreamIVARS *ivars, uint64_t value); // Flush content in the buffer to the FileHandle. static void @@ -287,11 +291,16 @@ OutStream_Write_F64_IMP(OutStream *self, double value) { void OutStream_Write_C32_IMP(OutStream *self, uint32_t value) { - SI_write_c32(self, OutStream_IVARS(self), value); + SI_write_cu32(self, OutStream_IVARS(self), value); +} + +void +OutStream_Write_CU32_IMP(OutStream *self, uint32_t value) { + SI_write_cu32(self, OutStream_IVARS(self), value); } static CFISH_INLINE void -SI_write_c32(OutStream *self, OutStreamIVARS *ivars, uint32_t value) { +SI_write_cu32(OutStream *self, OutStreamIVARS *ivars, uint32_t value) { uint8_t buf[C32_MAX_BYTES]; uint8_t *ptr = buf + sizeof(buf) - 1; @@ -310,7 +319,16 @@ SI_write_c32(OutStream *self, OutStreamIVARS *ivars, uint32_t value) { void OutStream_Write_C64_IMP(OutStream *self, uint64_t value) { - OutStreamIVARS *const ivars = OutStream_IVARS(self); + SI_write_cu64(self, OutStream_IVARS(self), value); +} + +void +OutStream_Write_CU64_IMP(OutStream *self, uint64_t value) { + SI_write_cu64(self, OutStream_IVARS(self), value); +} + +static CFISH_INLINE void +SI_write_cu64(OutStream *self, OutStreamIVARS *ivars, uint64_t value) { uint8_t buf[C64_MAX_BYTES]; uint8_t *ptr = buf + sizeof(buf) - 1; @@ -330,7 +348,7 @@ OutStream_Write_C64_IMP(OutStream *self, uint64_t value) { void OutStream_Write_String_IMP(OutStream *self, const char *string, size_t len) { OutStreamIVARS *const ivars = OutStream_IVARS(self); - SI_write_c32(self, ivars, (uint32_t)len); + SI_write_cu32(self, ivars, (uint32_t)len); SI_write_bytes(self, ivars, string, len); } http://git-wip-us.apache.org/repos/asf/lucy/blob/8a48ef58/core/Lucy/Store/OutStream.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Store/OutStream.cfh b/core/Lucy/Store/OutStream.cfh index 6bcacac..3726101 100644 --- a/core/Lucy/Store/OutStream.cfh +++ b/core/Lucy/Store/OutStream.cfh @@ -118,11 +118,21 @@ class Lucy::Store::OutStream inherits Clownfish::Obj { final void Write_C32(OutStream *self, uint32_t value); + /** Write an unsigned 32-bit integer using a compressed format. + */ + final void + Write_CU32(OutStream *self, uint32_t value); + /** Write a 64-bit integer using a compressed format. */ final void Write_C64(OutStream *self, uint64_t value); + /** Write an unsigned 64-bit integer using a compressed format. + */ + final void + Write_CU64(OutStream *self, uint64_t value); + /** Write an IEEE 764 32-bit floating point number in big-endian byte * order. */ http://git-wip-us.apache.org/repos/asf/lucy/blob/8a48ef58/core/Lucy/Test/Store/TestIOPrimitives.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Test/Store/TestIOPrimitives.c b/core/Lucy/Test/Store/TestIOPrimitives.c index 551f1ac..7409d7e 100644 --- a/core/Lucy/Test/Store/TestIOPrimitives.c +++ b/core/Lucy/Test/Store/TestIOPrimitives.c @@ -242,7 +242,7 @@ test_u64(TestBatchRunner *runner) { } static void -test_c32(TestBatchRunner *runner) { +test_cu32(TestBatchRunner *runner) { uint64_t *ints = TestUtils_random_u64s(NULL, 1000, 0, UINT32_MAX); RAMFile *file = RAMFile_new(NULL, false); OutStream *outstream = OutStream_open((Obj*)file); @@ -256,21 +256,21 @@ test_c32(TestBatchRunner *runner) { ints[3] = UINT32_MAX - 1; for (i = 0; i < 1000; i++) { - OutStream_Write_C32(outstream, (uint32_t)ints[i]); + OutStream_Write_CU32(outstream, (uint32_t)ints[i]); } OutStream_Close(outstream); instream = InStream_open((Obj*)file); for (i = 0; i < 1000; i++) { - uint32_t got = InStream_Read_C32(instream); + uint32_t got = InStream_Read_CU32(instream); if (got != ints[i]) { - FAIL(runner, "c32 round trip failed: %lu, %lu", (unsigned long)got, + FAIL(runner, "cu32 round trip failed: %lu, %lu", (unsigned long)got, (unsigned long)ints[i]); break; } } if (i == 1000) { - PASS(runner, "c32 round trip"); + PASS(runner, "cu32 round trip"); } DECREF(instream); @@ -280,7 +280,7 @@ test_c32(TestBatchRunner *runner) { } static void -test_c64(TestBatchRunner *runner) { +test_cu64(TestBatchRunner *runner) { uint64_t *ints = TestUtils_random_u64s(NULL, 1000, 0, UINT64_MAX); RAMFile *file = RAMFile_new(NULL, false); RAMFile *raw_file = RAMFile_new(NULL, false); @@ -297,23 +297,23 @@ test_c64(TestBatchRunner *runner) { ints[3] = UINT64_MAX - 1; for (i = 0; i < 1000; i++) { - OutStream_Write_C64(outstream, ints[i]); - OutStream_Write_C64(raw_outstream, ints[i]); + OutStream_Write_CU64(outstream, ints[i]); + OutStream_Write_CU64(raw_outstream, ints[i]); } OutStream_Close(outstream); OutStream_Close(raw_outstream); instream = InStream_open((Obj*)file); for (i = 0; i < 1000; i++) { - uint64_t got = InStream_Read_C64(instream); + uint64_t got = InStream_Read_CU64(instream); if (got != ints[i]) { - FAIL(runner, "c64 round trip failed: %" PRIu64 ", %" PRIu64, + FAIL(runner, "cu64 round trip failed: %" PRIu64 ", %" PRIu64, got, ints[i]); break; } } if (i == 1000) { - PASS(runner, "c64 round trip"); + PASS(runner, "cu64 round trip"); } raw_instream = InStream_open((Obj*)raw_file); @@ -429,8 +429,8 @@ TestIOPrimitives_Run_IMP(TestIOPrimitives *self, TestBatchRunner *runner) { test_u32(runner); test_i64(runner); test_u64(runner); - test_c32(runner); - test_c64(runner); + test_cu32(runner); + test_cu64(runner); test_f32(runner); test_f64(runner); }