You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/05/12 20:01:17 UTC
[1/6] lucy-clownfish git commit: Remove NumberUtils
Repository: lucy-clownfish
Updated Branches:
refs/heads/master 603c26133 -> 904bfa999
Remove NumberUtils
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/904bfa99
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/904bfa99
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/904bfa99
Branch: refs/heads/master
Commit: 904bfa999b7edb67afb93e30f317d21892d6fd7b
Parents: 8f811c4
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat May 9 17:51:24 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 19:57:45 2015 +0200
----------------------------------------------------------------------
runtime/core/Clownfish/Test.c | 2 -
.../core/Clownfish/Test/Util/TestNumberUtils.c | 379 ---------------
.../Clownfish/Test/Util/TestNumberUtils.cfh | 29 --
runtime/core/Clownfish/Util/NumberUtils.cfh | 466 -------------------
runtime/perl/t/core/030-number_utils.t | 25 -
5 files changed, 901 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/904bfa99/runtime/core/Clownfish/Test.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test.c b/runtime/core/Clownfish/Test.c
index cef3508..4212bff 100644
--- a/runtime/core/Clownfish/Test.c
+++ b/runtime/core/Clownfish/Test.c
@@ -36,7 +36,6 @@
#include "Clownfish/Test/TestVector.h"
#include "Clownfish/Test/Util/TestAtomic.h"
#include "Clownfish/Test/Util/TestMemory.h"
-#include "Clownfish/Test/Util/TestNumberUtils.h"
#include "Clownfish/Test/Util/TestStringHelper.h"
TestSuite*
@@ -52,7 +51,6 @@ Test_create_test_suite() {
TestSuite_Add_Batch(suite, (TestBatch*)TestBB_new());
TestSuite_Add_Batch(suite, (TestBatch*)TestStr_new());
TestSuite_Add_Batch(suite, (TestBatch*)TestCB_new());
- TestSuite_Add_Batch(suite, (TestBatch*)TestNumUtil_new());
TestSuite_Add_Batch(suite, (TestBatch*)TestNum_new());
TestSuite_Add_Batch(suite, (TestBatch*)TestStrHelp_new());
TestSuite_Add_Batch(suite, (TestBatch*)TestAtomic_new());
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/904bfa99/runtime/core/Clownfish/Test/Util/TestNumberUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/Util/TestNumberUtils.c b/runtime/core/Clownfish/Test/Util/TestNumberUtils.c
deleted file mode 100644
index adc529a..0000000
--- a/runtime/core/Clownfish/Test/Util/TestNumberUtils.c
+++ /dev/null
@@ -1,379 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <time.h>
-
-#define CFISH_USE_SHORT_NAMES
-#define TESTCFISH_USE_SHORT_NAMES
-
-#include "charmony.h"
-
-#include "Clownfish/Test/Util/TestNumberUtils.h"
-
-#include "Clownfish/Err.h"
-#include "Clownfish/Test.h"
-#include "Clownfish/TestHarness/TestBatchRunner.h"
-#include "Clownfish/TestHarness/TestUtils.h"
-#include "Clownfish/Util/Memory.h"
-#include "Clownfish/Util/NumberUtils.h"
-#include "Clownfish/Class.h"
-
-TestNumberUtils*
-TestNumUtil_new() {
- return (TestNumberUtils*)Class_Make_Obj(TESTNUMBERUTILS);
-}
-
-static void
-test_u1(TestBatchRunner *runner) {
- size_t count = 64;
- uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, 2);
- size_t amount = count / 8;
- uint8_t *bits = (uint8_t*)CALLOCATE(amount, sizeof(uint8_t));
-
- for (size_t i = 0; i < count; i++) {
- if (ints[i]) { NumUtil_u1set(bits, i); }
- }
- for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(runner, NumUtil_u1get(bits, i), (long)ints[i],
- "u1 set/get");
- }
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_u1flip(bits, i);
- }
- for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(runner, NumUtil_u1get(bits, i), !ints[i], "u1 flip");
- }
-
- FREEMEM(bits);
- FREEMEM(ints);
-}
-
-static void
-test_u2(TestBatchRunner *runner) {
- size_t count = 32;
- uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, 4);
- uint8_t *bits = (uint8_t*)CALLOCATE((count / 4), sizeof(uint8_t));
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_u2set(bits, i, (uint8_t)ints[i]);
- }
- for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(runner, NumUtil_u2get(bits, i), (long)ints[i], "u2");
- }
-
- FREEMEM(bits);
- FREEMEM(ints);
-}
-
-static void
-test_u4(TestBatchRunner *runner) {
- size_t count = 128;
- uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, 16);
- uint8_t *bits = (uint8_t*)CALLOCATE((count / 2), sizeof(uint8_t));
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_u4set(bits, i, (uint8_t)ints[i]);
- }
- for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(runner, NumUtil_u4get(bits, i), (long)ints[i], "u4");
- }
-
- FREEMEM(bits);
- FREEMEM(ints);
-}
-
-static void
-test_c32(TestBatchRunner *runner) {
- uint64_t mins[] = { 0, 0x4000 - 100, (uint32_t)INT32_MAX - 100, UINT32_MAX - 10 };
- uint64_t limits[] = { 500, 0x4000 + 100, (uint32_t)INT32_MAX + 100, UINT32_MAX };
- uint32_t set_num;
- uint32_t num_sets = sizeof(mins) / sizeof(uint64_t);
- size_t count = 64;
- uint64_t *ints = NULL;
- size_t amount = count * C32_MAX_BYTES;
- char *encoded = (char*)CALLOCATE(amount, sizeof(char));
- char *target = encoded;
- char *limit = target + amount;
- const char *decode;
-
- for (set_num = 0; set_num < num_sets; set_num++) {
- const char *skip;
- ints = TestUtils_random_u64s(ints, count,
- mins[set_num], limits[set_num]);
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_c32((uint32_t)ints[i], &target);
- }
- decode = encoded;
- skip = encoded;
- for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(runner, NumUtil_decode_c32(&decode), (long)ints[i],
- "c32 %lu", (long)ints[i]);
- NumUtil_skip_cint(&skip);
- if (decode > limit) { THROW(ERR, "overrun"); }
- }
- TEST_TRUE(runner, skip == decode, "skip %lu == %lu",
- (unsigned long)skip, (unsigned long)decode);
-
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_padded_c32((uint32_t)ints[i], &target);
- }
- TEST_TRUE(runner, target == limit,
- "padded c32 uses 5 bytes (%lu == %lu)", (unsigned long)target,
- (unsigned long)limit);
- decode = encoded;
- skip = encoded;
- for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(runner, NumUtil_decode_c32(&decode), (long)ints[i],
- "padded c32 %lu", (long)ints[i]);
- NumUtil_skip_cint(&skip);
- if (decode > limit) { THROW(ERR, "overrun"); }
- }
- TEST_TRUE(runner, skip == decode, "skip padded %lu == %lu",
- (unsigned long)skip, (unsigned long)decode);
- }
-
- target = encoded;
- NumUtil_encode_c32(UINT32_MAX, &target);
- decode = encoded;
- TEST_INT_EQ(runner, NumUtil_decode_c32(&decode), UINT32_MAX, "c32 UINT32_MAX");
-
- FREEMEM(encoded);
- FREEMEM(ints);
-}
-
-static void
-test_c64(TestBatchRunner *runner) {
- uint64_t mins[] = { 0, 0x4000 - 100, (uint64_t)UINT32_MAX - 100, UINT64_MAX - 10 };
- uint64_t limits[] = { 500, 0x4000 + 100, (uint64_t)UINT32_MAX + 1000, UINT64_MAX };
- uint32_t set_num;
- uint32_t num_sets = sizeof(mins) / sizeof(uint64_t);
- size_t count = 64;
- uint64_t *ints = NULL;
- size_t amount = count * C64_MAX_BYTES;
- char *encoded = (char*)CALLOCATE(amount, sizeof(char));
- char *target = encoded;
- char *limit = target + amount;
- const char *decode;
-
- for (set_num = 0; set_num < num_sets; set_num++) {
- const char *skip;
- ints = TestUtils_random_u64s(ints, count,
- mins[set_num], limits[set_num]);
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_c64(ints[i], &target);
- }
- decode = encoded;
- skip = encoded;
- for (size_t i = 0; i < count; i++) {
- uint64_t got = NumUtil_decode_c64(&decode);
- TEST_TRUE(runner, got == ints[i],
- "c64 %" PRIu64 " == %" PRIu64, got, ints[i]);
- if (decode > limit) { THROW(ERR, "overrun"); }
- NumUtil_skip_cint(&skip);
- }
- TEST_TRUE(runner, skip == decode, "skip %lu == %lu",
- (unsigned long)skip, (unsigned long)decode);
- }
-
- target = encoded;
- NumUtil_encode_c64(UINT64_MAX, &target);
-
- decode = encoded;
- uint64_t got = NumUtil_decode_c64(&decode);
- TEST_TRUE(runner, got == UINT64_MAX, "c64 UINT64_MAX");
-
- FREEMEM(encoded);
- FREEMEM(ints);
-}
-
-static void
-test_bigend_u16(TestBatchRunner *runner) {
- size_t count = 32;
- uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, UINT16_MAX + 1);
- size_t amount = (count + 1) * sizeof(uint16_t);
- char *allocated = (char*)CALLOCATE(amount, sizeof(char));
- char *encoded = allocated + 1; // Intentionally misaligned.
- char *target = encoded;
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_bigend_u16((uint16_t)ints[i], &target);
- target += sizeof(uint16_t);
- }
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- uint16_t got = NumUtil_decode_bigend_u16(target);
- TEST_INT_EQ(runner, got, (long)ints[i], "bigend u16");
- target += sizeof(uint16_t);
- }
-
- target = encoded;
- NumUtil_encode_bigend_u16(1, &target);
- TEST_INT_EQ(runner, encoded[0], 0, "Truly big-endian u16");
- TEST_INT_EQ(runner, encoded[1], 1, "Truly big-endian u16");
-
- FREEMEM(allocated);
- FREEMEM(ints);
-}
-
-static void
-test_bigend_u32(TestBatchRunner *runner) {
- size_t count = 32;
- uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, UINT64_C(1) + UINT32_MAX);
- size_t amount = (count + 1) * sizeof(uint32_t);
- char *allocated = (char*)CALLOCATE(amount, sizeof(char));
- char *encoded = allocated + 1; // Intentionally misaligned.
- char *target = encoded;
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_bigend_u32((uint32_t)ints[i], &target);
- target += sizeof(uint32_t);
- }
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- uint32_t got = NumUtil_decode_bigend_u32(target);
- TEST_INT_EQ(runner, got, (long)ints[i], "bigend u32");
- target += sizeof(uint32_t);
- }
-
- target = encoded;
- NumUtil_encode_bigend_u32(1, &target);
- TEST_INT_EQ(runner, encoded[0], 0, "Truly big-endian u32");
- TEST_INT_EQ(runner, encoded[3], 1, "Truly big-endian u32");
-
- FREEMEM(allocated);
- FREEMEM(ints);
-}
-
-static void
-test_bigend_u64(TestBatchRunner *runner) {
- size_t count = 32;
- uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, UINT64_MAX);
- size_t amount = (count + 1) * sizeof(uint64_t);
- char *allocated = (char*)CALLOCATE(amount, sizeof(char));
- char *encoded = allocated + 1; // Intentionally misaligned.
- char *target = encoded;
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_bigend_u64(ints[i], &target);
- target += sizeof(uint64_t);
- }
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- uint64_t got = NumUtil_decode_bigend_u64(target);
- TEST_TRUE(runner, got == ints[i], "bigend u64");
- target += sizeof(uint64_t);
- }
-
- target = encoded;
- NumUtil_encode_bigend_u64(1, &target);
- TEST_INT_EQ(runner, encoded[0], 0, "Truly big-endian");
- TEST_INT_EQ(runner, encoded[7], 1, "Truly big-endian");
-
- FREEMEM(allocated);
- FREEMEM(ints);
-}
-
-static void
-test_bigend_f32(TestBatchRunner *runner) {
- float source[] = { -1.3f, 0.0f, 100.2f };
- size_t count = 3;
- size_t amount = (count + 1) * sizeof(float);
- uint8_t *allocated = (uint8_t*)CALLOCATE(amount, sizeof(uint8_t));
- uint8_t *encoded = allocated + 1; // Intentionally misaligned.
- uint8_t *target = encoded;
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_bigend_f32(source[i], &target);
- target += sizeof(float);
- }
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- float got = NumUtil_decode_bigend_f32(target);
- TEST_TRUE(runner, got == source[i], "bigend f32");
- target += sizeof(float);
- }
-
- target = encoded;
- NumUtil_encode_bigend_f32(-2.0f, &target);
- TEST_INT_EQ(runner, (encoded[0] & 0x80), 0x80,
- "Truly big-endian (IEEE 754 sign bit set for negative number)");
- TEST_INT_EQ(runner, encoded[0], 0xC0,
- "IEEE 754 representation of -2.0f, byte 0");
- for (size_t i = 1; i < sizeof(float); i++) {
- TEST_INT_EQ(runner, encoded[i], 0,
- "IEEE 754 representation of -2.0f, byte %d", (int)i);
- }
-
- FREEMEM(allocated);
-}
-
-static void
-test_bigend_f64(TestBatchRunner *runner) {
- double source[] = { -1.3, 0.0, 100.2 };
- size_t count = 3;
- size_t amount = (count + 1) * sizeof(double);
- uint8_t *allocated = (uint8_t*)CALLOCATE(amount, sizeof(uint8_t));
- uint8_t *encoded = allocated + 1; // Intentionally misaligned.
- uint8_t *target = encoded;
-
- for (size_t i = 0; i < count; i++) {
- NumUtil_encode_bigend_f64(source[i], &target);
- target += sizeof(double);
- }
- target = encoded;
- for (size_t i = 0; i < count; i++) {
- double got = NumUtil_decode_bigend_f64(target);
- TEST_TRUE(runner, got == source[i], "bigend f64");
- target += sizeof(double);
- }
-
- target = encoded;
- NumUtil_encode_bigend_f64(-2.0, &target);
- TEST_INT_EQ(runner, (encoded[0] & 0x80), 0x80,
- "Truly big-endian (IEEE 754 sign bit set for negative number)");
- TEST_INT_EQ(runner, encoded[0], 0xC0,
- "IEEE 754 representation of -2.0, byte 0");
- for (size_t i = 1; i < sizeof(double); i++) {
- TEST_INT_EQ(runner, encoded[i], 0,
- "IEEE 754 representation of -2.0, byte %d", (int)i);
- }
-
- FREEMEM(allocated);
-}
-
-void
-TestNumUtil_Run_IMP(TestNumberUtils *self, TestBatchRunner *runner) {
- TestBatchRunner_Plan(runner, (TestBatch*)self, 1196);
- srand((unsigned int)time((time_t*)NULL));
- test_u1(runner);
- test_u2(runner);
- test_u4(runner);
- test_c32(runner);
- test_c64(runner);
- test_bigend_u16(runner);
- test_bigend_u32(runner);
- test_bigend_u64(runner);
- test_bigend_f32(runner);
- test_bigend_f64(runner);
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/904bfa99/runtime/core/Clownfish/Test/Util/TestNumberUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/Util/TestNumberUtils.cfh b/runtime/core/Clownfish/Test/Util/TestNumberUtils.cfh
deleted file mode 100644
index e50d81f..0000000
--- a/runtime/core/Clownfish/Test/Util/TestNumberUtils.cfh
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel TestClownfish;
-
-class Clownfish::Test::Util::TestNumberUtils nickname TestNumUtil
- inherits Clownfish::TestHarness::TestBatch {
-
- inert incremented TestNumberUtils*
- new();
-
- void
- Run(TestNumberUtils *self, TestBatchRunner *runner);
-}
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/904bfa99/runtime/core/Clownfish/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/NumberUtils.cfh b/runtime/core/Clownfish/Util/NumberUtils.cfh
deleted file mode 100644
index 13b4a92..0000000
--- a/runtime/core/Clownfish/Util/NumberUtils.cfh
+++ /dev/null
@@ -1,466 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-parcel Clownfish;
-
-/** Provide various number-related utilies.
- *
- * Provide utilities for dealing with endian issues, sub-byte-width arrays,
- * compressed integers, and so on.
- */
-inert class Clownfish::Util::NumberUtils nickname NumUtil {
-
- /** Encode an unsigned 16-bit integer as 2 bytes in the buffer provided,
- * using big-endian byte order.
- */
- inert inline void
- encode_bigend_u16(uint16_t value, void *dest);
-
- /** Encode an unsigned 32-bit integer as 4 bytes in the buffer provided,
- * using big-endian byte order.
- */
- inert inline void
- encode_bigend_u32(uint32_t value, void *dest);
-
- /** Encode an unsigned 64-bit integer as 8 bytes in the buffer provided,
- * using big-endian byte order.
- */
- inert inline void
- encode_bigend_u64(uint64_t value, void *dest);
-
- /** Interpret a sequence of bytes as a big-endian unsigned 16-bit int.
- */
- inert inline uint16_t
- decode_bigend_u16(const void *source);
-
- /** Interpret a sequence of bytes as a big-endian unsigned 32-bit int.
- */
- inert inline uint32_t
- decode_bigend_u32(const void *source);
-
- /** Interpret a sequence of bytes as a big-endian unsigned 64-bit int.
- */
- inert inline uint64_t
- decode_bigend_u64(const void *source);
-
- /** Encode a 32-bit floating point number as 4 bytes in the buffer
- * provided, using big-endian byte order.
- */
- inert inline void
- encode_bigend_f32(float value, void *dest);
-
- /** Encode a 64-bit floating point number as 8 bytes in the buffer
- * provided, using big-endian byte order.
- */
- inert inline void
- encode_bigend_f64(double value, void *dest);
-
- /** Interpret a sequence of bytes as a 32-bit float stored in big-endian
- * byte order.
- */
- inert inline float
- decode_bigend_f32(const void *source);
-
- /** Interpret a sequence of bytes as a 64-bit float stored in big-endian
- * byte order.
- */
- inert inline double
- decode_bigend_f64(const void *source);
-
- /** Encode a C32 at the space pointed to by `dest`. As a side
- * effect, `dest` will be advanced to immediately after the end
- * of the C32.
- */
- inert inline void
- encode_c32(uint32_t value, char **dest);
-
- /** Encode a C32 at the space pointed to by `dest`, but add
- * "leading zeroes" so that the space consumed will always be 5 bytes. As
- * a side effect, `dest` will be advanced to immediately after
- * the end of the C32.
- */
- inert inline void
- encode_padded_c32(uint32_t value, char **dest);
-
- /** Encode a C64 at the space pointed to by `dest`. As a side
- * effect, `dest` will be advanced to immediately after the end
- * of the C64.
- */
- inert inline void
- encode_c64(uint64_t value, char **dest);
-
- /** Read a C32 from the buffer pointed to by `source`. As a
- * side effect, advance the pointer, consuming the bytes occupied by the
- * C32.
- */
- inert inline uint32_t
- decode_c32(const char **source);
-
- /** Read a C64 from the buffer pointed to by `source`. As a
- * side effect, advance the pointer, consuming the bytes occupied by the
- * C64.
- */
- inert inline uint64_t
- decode_c64(const char **source);
-
- /** Advance `source` past one encoded C32 or C64.
- */
- inert inline void
- skip_cint(const char **source);
-
- /** Interpret `array` as an array of bits; return true if the
- * bit at `tick` is set, false otherwise.
- */
- inert inline bool
- u1get(const void *array, uint32_t tick);
-
- /** Interpret `array` as an array of bits; set the bit at
- * `tick`.
- */
- inert inline void
- u1set(void *array, uint32_t tick);
-
- /** Interpret `array` as an array of bits; clear the bit at
- * `tick`.
- */
- inert inline void
- u1clear(void *array, uint32_t tick);
-
- /** Interpret `array` as an array of bits; flip the bit at
- * `tick`.
- */
- inert inline void
- u1flip(void *array, uint32_t tick);
-
- /** Interpret `array` as an array of two-bit integers; return
- * the value at `tick`.
- */
- inert inline uint8_t
- u2get(const void *array, uint32_t tick);
-
- /** Interpret `array` as an array of two-bit integers; set the
- * element at `tick` to `value`.
- */
- inert inline void
- u2set(void *array, uint32_t tick, uint8_t value);
-
- /** Interpret `array` as an array of four-bit integers; return
- * the value at `tick`.
- */
- inert inline uint8_t
- u4get(const void *array, uint32_t tick);
-
- /** Interpret `array` as an array of four-bit integers; set the
- * element at `tick` to `value`.
- */
- inert inline void
- u4set(void *array, uint32_t tick, uint8_t value);
-}
-
-__C__
-
-#include <string.h>
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_bigend_u16(uint16_t value, void *dest_ptr) {
- uint8_t *dest = *(uint8_t**)dest_ptr;
-#ifdef CFISH_BIG_END
- memcpy(dest, &value, sizeof(uint16_t));
-#else /* little endian */
- uint8_t *source = (uint8_t*)&value;
- dest[0] = source[1];
- dest[1] = source[0];
-#endif /* CFISH_BIG_END (and little endian) */
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_bigend_u32(uint32_t value, void *dest_ptr) {
- uint8_t *dest = *(uint8_t**)dest_ptr;
-#ifdef CFISH_BIG_END
- memcpy(dest, &value, sizeof(uint32_t));
-#else /* little endian */
- uint8_t *source = (uint8_t*)&value;
- dest[0] = source[3];
- dest[1] = source[2];
- dest[2] = source[1];
- dest[3] = source[0];
-#endif /* CFISH_BIG_END (and little endian) */
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_bigend_u64(uint64_t value, void *dest_ptr) {
- uint8_t *dest = *(uint8_t**)dest_ptr;
-#ifdef CFISH_BIG_END
- memcpy(dest, &value, sizeof(uint64_t));
-#else /* little endian */
- uint8_t *source = (uint8_t*)&value;
- dest[0] = source[7];
- dest[1] = source[6];
- dest[2] = source[5];
- dest[3] = source[4];
- dest[4] = source[3];
- dest[5] = source[2];
- dest[6] = source[1];
- dest[7] = source[0];
-#endif /* CFISH_BIG_END (and little endian) */
-}
-
-static CFISH_INLINE uint16_t
-cfish_NumUtil_decode_bigend_u16(const void *source) {
- const uint8_t *const buf = (const uint8_t*)source;
- return ((uint16_t)buf[0] << 8) |
- ((uint16_t)buf[1]);
-}
-
-static CFISH_INLINE uint32_t
-cfish_NumUtil_decode_bigend_u32(const void *source) {
- const uint8_t *const buf = (const uint8_t*)source;
- return ((uint32_t)buf[0] << 24) |
- ((uint32_t)buf[1] << 16) |
- ((uint32_t)buf[2] << 8) |
- ((uint32_t)buf[3]);
-}
-
-static CFISH_INLINE uint64_t
-cfish_NumUtil_decode_bigend_u64(const void *source) {
- const uint8_t *const buf = (const uint8_t*)source;
- uint64_t high_bits = ((uint32_t)buf[0] << 24) |
- ((uint32_t)buf[1] << 16) |
- ((uint32_t)buf[2] << 8) |
- ((uint32_t)buf[3]);
- uint32_t low_bits = ((uint32_t)buf[4] << 24) |
- ((uint32_t)buf[5] << 16) |
- ((uint32_t)buf[6] << 8) |
- ((uint32_t)buf[7]);
- uint64_t retval = high_bits << 32;
- retval |= low_bits;
- return retval;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_bigend_f32(float value, void *dest_ptr) {
- uint8_t *dest = *(uint8_t**)dest_ptr;
-#ifdef CFISH_BIG_END
- memcpy(dest, &value, sizeof(float));
-#else
- union { float f; uint32_t u32; } duo;
- duo.f = value;
- cfish_NumUtil_encode_bigend_u32(duo.u32, &dest);
-#endif
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_bigend_f64(double value, void *dest_ptr) {
- uint8_t *dest = *(uint8_t**)dest_ptr;
-#ifdef CFISH_BIG_END
- memcpy(dest, &value, sizeof(double));
-#else
- union { double d; uint64_t u64; } duo;
- duo.d = value;
- cfish_NumUtil_encode_bigend_u64(duo.u64, &dest);
-#endif
-}
-
-static CFISH_INLINE float
-cfish_NumUtil_decode_bigend_f32(const void *source) {
- union { float f; uint32_t u32; } duo;
- memcpy(&duo, source, sizeof(float));
-#ifdef CFISH_LITTLE_END
- duo.u32 = cfish_NumUtil_decode_bigend_u32(&duo.u32);
-#endif
- return duo.f;
-}
-
-static CFISH_INLINE double
-cfish_NumUtil_decode_bigend_f64(const void *source) {
- union { double d; uint64_t u64; } duo;
- memcpy(&duo, source, sizeof(double));
-#ifdef CFISH_LITTLE_END
- duo.u64 = cfish_NumUtil_decode_bigend_u64(&duo.u64);
-#endif
- return duo.d;
-}
-
-#define CFISH_NUMUTIL_C32_MAX_BYTES ((sizeof(uint32_t) * 8 / 7) + 1) /* 5 */
-#define CFISH_NUMUTIL_C64_MAX_BYTES ((sizeof(uint64_t) * 8 / 7) + 1) /* 10 */
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_c32(uint32_t value, char **out_buf) {
- uint8_t buf[CFISH_NUMUTIL_C32_MAX_BYTES];
- uint8_t *const limit = buf + sizeof(buf);
- uint8_t *ptr = limit - 1;
- int num_bytes;
- /* Write last byte first, which has no continue bit. */
- *ptr = value & 0x7f;
- value >>= 7;
- while (value) {
- /* Work backwards, writing bytes with continue bits set. */
- *--ptr = ((value & 0x7f) | 0x80);
- value >>= 7;
- }
- num_bytes = limit - ptr;
- memcpy(*out_buf, ptr, num_bytes);
- *out_buf += num_bytes;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_c64(uint64_t value, char **out_buf) {
- uint8_t buf[CFISH_NUMUTIL_C64_MAX_BYTES];
- uint8_t *const limit = buf + sizeof(buf);
- uint8_t *ptr = limit - 1;
- int num_bytes;
- /* Write last byte first, which has no continue bit. */
- *ptr = value & 0x7f;
- value >>= 7;
- while (value) {
- /* Work backwards, writing bytes with continue bits set. */
- *--ptr = ((value & 0x7f) | 0x80);
- value >>= 7;
- }
- num_bytes = limit - ptr;
- memcpy(*out_buf, ptr, num_bytes);
- *out_buf += num_bytes;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_encode_padded_c32(uint32_t value, char **out_buf) {
- uint8_t buf[CFISH_NUMUTIL_C32_MAX_BYTES]
- = { 0x80, 0x80, 0x80, 0x80, 0x80 };
- uint8_t *const limit = buf + sizeof(buf);
- uint8_t *ptr = limit - 1;
- /* Write last byte first, which has no continue bit. */
- *ptr = value & 0x7f;
- value >>= 7;
- while (value) {
- /* Work backwards, writing bytes with continue bits set. */
- *--ptr = ((value & 0x7f) | 0x80);
- value >>= 7;
- }
- memcpy(*out_buf, buf, CFISH_NUMUTIL_C32_MAX_BYTES);
- *out_buf += sizeof(buf);
-}
-
-/* Decode a compressed integer up to size of 'var', advancing 'source' */
-#define CFISH_NUMUTIL_DECODE_CINT(var, source) \
- do { \
- var = (*source & 0x7f); \
- while (*source++ & 0x80) { \
- var = (*source & 0x7f) | (var << 7); \
- } \
- } while (0)
-
-static CFISH_INLINE uint32_t
-cfish_NumUtil_decode_c32(const char **source_ptr) {
- const char *source = *source_ptr;
- uint32_t decoded;
- CFISH_NUMUTIL_DECODE_CINT(decoded, source);
- *source_ptr = source;
- return decoded;
-}
-
-static CFISH_INLINE uint64_t
-cfish_NumUtil_decode_c64(const char **source_ptr) {
- const char *source = *source_ptr;
- uint64_t decoded;
- CFISH_NUMUTIL_DECODE_CINT(decoded, source);
- *source_ptr = source;
- return decoded;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_skip_cint(const char **source_ptr) {
- const uint8_t *ptr = *(const uint8_t**)source_ptr;
- while ((*ptr++ & 0x80) != 0) { }
- *source_ptr = (const char*)ptr;
-}
-
-static CFISH_INLINE bool
-cfish_NumUtil_u1get(const void *array, uint32_t tick) {
- uint8_t *const u8bits = (uint8_t*)array;
- const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = 1 << (tick & 0x7);
- return !((u8bits[byte_offset] & mask) == 0);
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_u1set(void *array, uint32_t tick) {
- uint8_t *const u8bits = (uint8_t*)array;
- const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = 1 << (tick & 0x7);
- u8bits[byte_offset] |= mask;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_u1clear(void *array, uint32_t tick) {
- uint8_t *const u8bits = (uint8_t*)array;
- const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = 1 << (tick & 0x7);
- u8bits[byte_offset] &= ~mask;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_u1flip(void *array, uint32_t tick) {
- uint8_t *const u8bits = (uint8_t*)array;
- const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = 1 << (tick & 0x7);
- u8bits[byte_offset] ^= mask;
-}
-
-static CFISH_INLINE uint8_t
-cfish_NumUtil_u2get(const void *array, uint32_t tick) {
- uint8_t *ints = (uint8_t*)array;
- uint8_t byte = ints[(tick >> 2)];
- int shift = 2 * (tick & 0x3);
- return (byte >> shift) & 0x3;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_u2set(void *array, uint32_t tick, uint8_t value) {
- uint8_t *ints = (uint8_t*)array;
- int shift = 2 * (tick & 0x3);
- uint8_t mask = 0x3 << shift;
- uint8_t new_val = value & 0x3;
- uint8_t new_bits = new_val << shift;
- ints[(tick >> 2)] = (ints[(tick >> 2)] & ~mask) | new_bits;
-}
-
-
-static CFISH_INLINE uint8_t
-cfish_NumUtil_u4get(const void *array, uint32_t tick) {
- uint8_t *ints = (uint8_t*)array;
- uint8_t byte = ints[(tick >> 1)];
- int shift = 4 * (tick & 1);
- return (byte >> shift) & 0xF;
-}
-
-static CFISH_INLINE void
-cfish_NumUtil_u4set(void *array, uint32_t tick, uint8_t value) {
- uint8_t *ints = (uint8_t*)array;
- int shift = 4 * (tick & 0x1);
- uint8_t mask = 0xF << shift;
- uint8_t new_val = value & 0xF;
- uint8_t new_bits = new_val << shift;
- ints[(tick >> 1)] = (ints[(tick >> 1)] & ~mask) | new_bits;
-}
-
-#ifdef CFISH_USE_SHORT_NAMES
- #define C32_MAX_BYTES CFISH_NUMUTIL_C32_MAX_BYTES
- #define C64_MAX_BYTES CFISH_NUMUTIL_C64_MAX_BYTES
-#endif
-
-__END_C__
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/904bfa99/runtime/perl/t/core/030-number_utils.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/core/030-number_utils.t b/runtime/perl/t/core/030-number_utils.t
deleted file mode 100644
index 1035f96..0000000
--- a/runtime/perl/t/core/030-number_utils.t
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-use strict;
-use warnings;
-
-use Clownfish::Test;
-my $success = Clownfish::Test::run_tests(
- "Clownfish::Test::Util::TestNumberUtils"
-);
-
-exit($success ? 0 : 1);
-
[4/6] lucy-clownfish git commit: Make String and StringIterator final
Posted by nw...@apache.org.
Make String and StringIterator final
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/1e30e5ad
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/1e30e5ad
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/1e30e5ad
Branch: refs/heads/master
Commit: 1e30e5adf6250a3170b5a6628ec3f9164a414979
Parents: 2bff781
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue May 12 18:58:24 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 19:57:45 2015 +0200
----------------------------------------------------------------------
runtime/core/Clownfish/String.cfh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1e30e5ad/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/String.cfh b/runtime/core/Clownfish/String.cfh
index 64e7d22..478ad19 100644
--- a/runtime/core/Clownfish/String.cfh
+++ b/runtime/core/Clownfish/String.cfh
@@ -20,7 +20,7 @@ parcel Clownfish;
* Immutable string holding Unicode characters.
*/
-class Clownfish::String nickname Str
+final class Clownfish::String nickname Str
inherits Clownfish::Obj {
const char *ptr;
@@ -275,7 +275,7 @@ class Clownfish::String nickname Str
Tail(String *self);
}
-class Clownfish::StringIterator nickname StrIter
+final class Clownfish::StringIterator nickname StrIter
inherits Clownfish::Obj {
String *string;
[5/6] lucy-clownfish git commit: Remove unneeded #include
Posted by nw...@apache.org.
Remove unneeded #include
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/8f811c47
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/8f811c47
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/8f811c47
Branch: refs/heads/master
Commit: 8f811c47311a758056f2b9b50666020481b098ad
Parents: 64310b4
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat May 9 17:42:58 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 19:57:45 2015 +0200
----------------------------------------------------------------------
runtime/ruby/ext/Bind.c | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/8f811c47/runtime/ruby/ext/Bind.c
----------------------------------------------------------------------
diff --git a/runtime/ruby/ext/Bind.c b/runtime/ruby/ext/Bind.c
index edf0fa9..fa8a130 100644
--- a/runtime/ruby/ext/Bind.c
+++ b/runtime/ruby/ext/Bind.c
@@ -17,7 +17,6 @@
#include "ruby.h"
#include "Bind.h"
#include "Clownfish/Util/StringHelper.h"
-#include "Clownfish/Util/NumberUtils.h"
VALUE
Bind_cfish_to_ruby(cfish_Obj *obj) {
[2/6] lucy-clownfish git commit: Private implementation of u1{get,
set} in XSBind.c
Posted by nw...@apache.org.
Private implementation of u1{get,set} in XSBind.c
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/64310b4f
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/64310b4f
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/64310b4f
Branch: refs/heads/master
Commit: 64310b4f038f9d01dea531db7d0d192f0ff8b596
Parents: c3cf1b3
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat May 9 17:27:32 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 19:57:45 2015 +0200
----------------------------------------------------------------------
runtime/perl/xs/XSBind.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/64310b4f/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index be0bf1b..4302f84 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -29,7 +29,6 @@
#include "Clownfish/TestHarness/TestBatchRunner.h"
#include "Clownfish/Util/Atomic.h"
#include "Clownfish/Util/StringHelper.h"
-#include "Clownfish/Util/NumberUtils.h"
#include "Clownfish/Util/Memory.h"
#define XSBIND_REFCOUNT_FLAG 1
@@ -515,6 +514,22 @@ S_extract_from_sv(pTHX_ SV *value, void *target, const char *label,
return true;
}
+static CFISH_INLINE bool
+S_u1get(const void *array, uint32_t tick) {
+ const uint8_t *const u8bits = (const uint8_t*)array;
+ const uint32_t byte_offset = tick >> 3;
+ const uint8_t mask = 1 << (tick & 0x7);
+ return (u8bits[byte_offset] & mask) != 0;
+}
+
+static CFISH_INLINE void
+S_u1set(void *array, uint32_t tick) {
+ uint8_t *const u8bits = (uint8_t*)array;
+ const uint32_t byte_offset = tick >> 3;
+ const uint8_t mask = 1 << (tick & 0x7);
+ u8bits[byte_offset] |= mask;
+}
+
bool
XSBind_allot_params(pTHX_ SV** stack, int32_t start, int32_t num_stack_elems,
...) {
@@ -553,7 +568,7 @@ XSBind_allot_params(pTHX_ SV** stack, int32_t start, int32_t num_stack_elems,
if (SvCUR(key_sv) == (STRLEN)label_len) {
if (memcmp(SvPVX(key_sv), label, label_len) == 0) {
found_arg = tick;
- cfish_NumUtil_u1set(verified_labels, tick);
+ S_u1set(verified_labels, tick);
}
}
}
@@ -584,7 +599,7 @@ XSBind_allot_params(pTHX_ SV** stack, int32_t start, int32_t num_stack_elems,
// Ensure that all parameter labels were valid.
for (int32_t tick = start; tick < num_stack_elems; tick += 2) {
- if (!cfish_NumUtil_u1get(verified_labels, tick)) {
+ if (!S_u1get(verified_labels, tick)) {
SV *const key_sv = stack[tick];
char *key = SvPV_nolen(key_sv);
cfish_String *mess
[3/6] lucy-clownfish git commit: Eliminate StupidHashString
Posted by nw...@apache.org.
Eliminate StupidHashString
Using a LockFreeRegistry with capacity 1 should have the same effect.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/2bff7818
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/2bff7818
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/2bff7818
Branch: refs/heads/master
Commit: 2bff78180371063549cabe3dbf1a4b04d7b31bd6
Parents: 603c261
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue May 12 19:04:39 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 19:57:45 2015 +0200
----------------------------------------------------------------------
.../core/Clownfish/Test/TestLockFreeRegistry.c | 37 +++++++-------------
.../Clownfish/Test/TestLockFreeRegistry.cfh | 11 ------
2 files changed, 12 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2bff7818/runtime/core/Clownfish/Test/TestLockFreeRegistry.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c
index 8f41f33..b030984 100644
--- a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c
+++ b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c
@@ -22,6 +22,7 @@
#include "Clownfish/Test/TestLockFreeRegistry.h"
#include "Clownfish/LockFreeRegistry.h"
+#include "Clownfish/String.h"
#include "Clownfish/Test.h"
#include "Clownfish/TestHarness/TestBatchRunner.h"
#include "Clownfish/Class.h"
@@ -31,42 +32,28 @@ TestLFReg_new() {
return (TestLockFreeRegistry*)Class_Make_Obj(TESTLOCKFREEREGISTRY);
}
-StupidHashString*
-StupidHashString_new(const char *text) {
- StupidHashString *self
- = (StupidHashString*)Class_Make_Obj(STUPIDHASHSTRING);
- return (StupidHashString*)Str_init_from_trusted_utf8((String*)self, text,
- strlen(text));
-}
-
-size_t
-StupidHashString_Hash_Sum_IMP(StupidHashString *self) {
- UNUSED_VAR(self);
- return 1;
-}
-
static void
test_all(TestBatchRunner *runner) {
- LockFreeRegistry *registry = LFReg_new(10);
- StupidHashString *foo = StupidHashString_new("foo");
- StupidHashString *bar = StupidHashString_new("bar");
- StupidHashString *baz = StupidHashString_new("baz");
- StupidHashString *foo_dupe = StupidHashString_new("foo");
+ LockFreeRegistry *registry = LFReg_new(1);
+ String *foo = Str_newf("foo");
+ String *bar = Str_newf("bar");
+ String *baz = Str_newf("baz");
+ String *foo_dupe = Str_newf("foo");
- TEST_TRUE(runner, LFReg_register(registry, (String*)foo, (Obj*)foo),
+ TEST_TRUE(runner, LFReg_register(registry, foo, (Obj*)foo),
"Register() returns true on success");
TEST_FALSE(runner,
- LFReg_register(registry, (String*)foo_dupe, (Obj*)foo_dupe),
+ LFReg_register(registry, foo_dupe, (Obj*)foo_dupe),
"Can't Register() keys that test equal");
- TEST_TRUE(runner, LFReg_register(registry, (String*)bar, (Obj*)bar),
+ TEST_TRUE(runner, LFReg_register(registry, bar, (Obj*)bar),
"Register() key with the same Hash_Sum but that isn't Equal");
- TEST_TRUE(runner, LFReg_fetch(registry, (String*)foo_dupe) == (Obj*)foo,
+ TEST_TRUE(runner, LFReg_fetch(registry, foo_dupe) == (Obj*)foo,
"Fetch()");
- TEST_TRUE(runner, LFReg_fetch(registry, (String*)bar) == (Obj*)bar,
+ TEST_TRUE(runner, LFReg_fetch(registry, bar) == (Obj*)bar,
"Fetch() again");
- TEST_TRUE(runner, LFReg_fetch(registry, (String*)baz) == NULL,
+ TEST_TRUE(runner, LFReg_fetch(registry, baz) == NULL,
"Fetch() non-existent key returns NULL");
DECREF(foo_dupe);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2bff7818/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh b/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh
index c2cca6e..784f745 100644
--- a/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh
+++ b/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh
@@ -26,15 +26,4 @@ class Clownfish::Test::TestLockFreeRegistry nickname TestLFReg
Run(TestLockFreeRegistry *self, TestBatchRunner *runner);
}
-/** Private test-only class for stressing LockFreeRegistry.
- */
-class Clownfish::Test::StupidHashString inherits Clownfish::String {
- inert incremented StupidHashString*
- new(const char *text);
-
- /** Always returns 1, guaranteeing collisions. */
- size_t
- Hash_Sum(StupidHashString *self);
-}
-
[6/6] lucy-clownfish git commit: Compute NumUtil shifts and masks
directly
Posted by nw...@apache.org.
Compute NumUtil shifts and masks directly
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/c3cf1b37
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/c3cf1b37
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/c3cf1b37
Branch: refs/heads/master
Commit: c3cf1b373fb7fa7d69b5937197de66ab8d84daa1
Parents: 1e30e5a
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat May 9 17:17:24 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue May 12 19:57:45 2015 +0200
----------------------------------------------------------------------
runtime/core/Clownfish/Util/NumberUtils.c | 34 ------------------------
runtime/core/Clownfish/Util/NumberUtils.cfh | 28 +++++++------------
2 files changed, 10 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c3cf1b37/runtime/core/Clownfish/Util/NumberUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/NumberUtils.c b/runtime/core/Clownfish/Util/NumberUtils.c
deleted file mode 100644
index c76b4d9..0000000
--- a/runtime/core/Clownfish/Util/NumberUtils.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define C_CFISH_NUMBERUTILS
-#define CFISH_USE_SHORT_NAMES
-
-#include <string.h>
-
-#include "Clownfish/Util/NumberUtils.h"
-
-const uint8_t NumUtil_u1masks[8] = {
- 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
-};
-
-const uint8_t NumUtil_u2shifts[4] = { 0x0, 0x2, 0x4, 0x6 };
-const uint8_t NumUtil_u2masks[4] = { 0x3, 0xC, 0x30, 0xC0 };
-
-const uint8_t NumUtil_u4shifts[2] = { 0x00, 0x04 };
-const uint8_t NumUtil_u4masks[2] = { 0x0F, 0xF0 };
-
-
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/c3cf1b37/runtime/core/Clownfish/Util/NumberUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Util/NumberUtils.cfh b/runtime/core/Clownfish/Util/NumberUtils.cfh
index efab6cb..13b4a92 100644
--- a/runtime/core/Clownfish/Util/NumberUtils.cfh
+++ b/runtime/core/Clownfish/Util/NumberUtils.cfh
@@ -23,12 +23,6 @@ parcel Clownfish;
*/
inert class Clownfish::Util::NumberUtils nickname NumUtil {
- inert const uint8_t[8] u1masks;
- inert const uint8_t[4] u2masks;
- inert const uint8_t[4] u2shifts;
- inert const uint8_t[2] u4masks;
- inert const uint8_t[2] u4shifts;
-
/** Encode an unsigned 16-bit integer as 2 bytes in the buffer provided,
* using big-endian byte order.
*/
@@ -397,7 +391,7 @@ static CFISH_INLINE bool
cfish_NumUtil_u1get(const void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
return !((u8bits[byte_offset] & mask) == 0);
}
@@ -405,7 +399,7 @@ static CFISH_INLINE void
cfish_NumUtil_u1set(void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
u8bits[byte_offset] |= mask;
}
@@ -413,7 +407,7 @@ static CFISH_INLINE void
cfish_NumUtil_u1clear(void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
u8bits[byte_offset] &= ~mask;
}
@@ -421,7 +415,7 @@ static CFISH_INLINE void
cfish_NumUtil_u1flip(void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
- const uint8_t mask = cfish_NumUtil_u1masks[tick & 0x7];
+ const uint8_t mask = 1 << (tick & 0x7);
u8bits[byte_offset] ^= mask;
}
@@ -429,16 +423,15 @@ static CFISH_INLINE uint8_t
cfish_NumUtil_u2get(const void *array, uint32_t tick) {
uint8_t *ints = (uint8_t*)array;
uint8_t byte = ints[(tick >> 2)];
- int shift = cfish_NumUtil_u2shifts[tick & 0x3];
+ int shift = 2 * (tick & 0x3);
return (byte >> shift) & 0x3;
}
static CFISH_INLINE void
cfish_NumUtil_u2set(void *array, uint32_t tick, uint8_t value) {
uint8_t *ints = (uint8_t*)array;
- unsigned sub_tick = tick & 0x3;
- int shift = cfish_NumUtil_u2shifts[sub_tick];
- uint8_t mask = cfish_NumUtil_u2masks[sub_tick];
+ int shift = 2 * (tick & 0x3);
+ uint8_t mask = 0x3 << shift;
uint8_t new_val = value & 0x3;
uint8_t new_bits = new_val << shift;
ints[(tick >> 2)] = (ints[(tick >> 2)] & ~mask) | new_bits;
@@ -449,16 +442,15 @@ static CFISH_INLINE uint8_t
cfish_NumUtil_u4get(const void *array, uint32_t tick) {
uint8_t *ints = (uint8_t*)array;
uint8_t byte = ints[(tick >> 1)];
- int shift = cfish_NumUtil_u4shifts[(tick & 1)];
+ int shift = 4 * (tick & 1);
return (byte >> shift) & 0xF;
}
static CFISH_INLINE void
cfish_NumUtil_u4set(void *array, uint32_t tick, uint8_t value) {
uint8_t *ints = (uint8_t*)array;
- unsigned sub_tick = tick & 0x1;
- int shift = cfish_NumUtil_u4shifts[sub_tick];
- uint8_t mask = cfish_NumUtil_u4masks[sub_tick];
+ int shift = 4 * (tick & 0x1);
+ uint8_t mask = 0xF << shift;
uint8_t new_val = value & 0xF;
uint8_t new_bits = new_val << shift;
ints[(tick >> 1)] = (ints[(tick >> 1)] & ~mask) | new_bits;