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 2011/05/02 01:50:38 UTC
[lucy-commits] svn commit: r1098445 [21/23] - in /incubator/lucy/trunk: charmonizer/
charmonizer/src/Charmonizer/ charmonizer/src/Charmonizer/Core/
charmonizer/src/Charmonizer/Probe/ charmonizer/src/Charmonizer/Test/
clownfish/lib/ clownfish/lib/Clownfish/Binding/ cl...
Modified: incubator/lucy/trunk/core/Lucy/Test/TestUtils.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/TestUtils.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/TestUtils.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/TestUtils.c Sun May 1 23:50:24 2011
@@ -37,19 +37,18 @@
#include "Lucy/Util/Freezer.h"
uint64_t
-TestUtils_random_u64()
-{
- uint64_t num = ((uint64_t)rand() << 60)
+TestUtils_random_u64() {
+ uint64_t num = ((uint64_t)rand() << 60)
| ((uint64_t)rand() << 45)
| ((uint64_t)rand() << 30)
- | ((uint64_t)rand() << 15)
+ | ((uint64_t)rand() << 15)
| ((uint64_t)rand() << 0);
return num;
}
int64_t*
-TestUtils_random_i64s(int64_t *buf, size_t count, int64_t min, int64_t limit)
-{
+TestUtils_random_i64s(int64_t *buf, size_t count, int64_t min,
+ int64_t limit) {
uint64_t range = min < limit ? limit - min : 0;
int64_t *ints = buf ? buf : (int64_t*)CALLOCATE(count, sizeof(int64_t));
size_t i;
@@ -60,8 +59,8 @@ TestUtils_random_i64s(int64_t *buf, size
}
uint64_t*
-TestUtils_random_u64s(uint64_t *buf, size_t count, uint64_t min, uint64_t limit)
-{
+TestUtils_random_u64s(uint64_t *buf, size_t count, uint64_t min,
+ uint64_t limit) {
uint64_t range = min < limit ? limit - min : 0;
uint64_t *ints = buf ? buf : (uint64_t*)CALLOCATE(count, sizeof(uint64_t));
size_t i;
@@ -72,8 +71,7 @@ TestUtils_random_u64s(uint64_t *buf, siz
}
double*
-TestUtils_random_f64s(double *buf, size_t count)
-{
+TestUtils_random_f64s(double *buf, size_t count) {
double *f64s = buf ? buf : (double*)CALLOCATE(count, sizeof(double));
size_t i;
for (i = 0; i < count; i++) {
@@ -84,8 +82,7 @@ TestUtils_random_f64s(double *buf, size_
}
VArray*
-TestUtils_doc_set()
-{
+TestUtils_doc_set() {
VArray *docs = VA_new(10);
VA_Push(docs, (Obj*)TestUtils_get_cb("x"));
@@ -95,19 +92,17 @@ TestUtils_doc_set()
VA_Push(docs, (Obj*)TestUtils_get_cb("x a b"));
VA_Push(docs, (Obj*)TestUtils_get_cb("x a b c"));
VA_Push(docs, (Obj*)TestUtils_get_cb("x foo a b c d"));
-
+
return docs;
}
CharBuf*
-TestUtils_get_cb(const char *ptr)
-{
+TestUtils_get_cb(const char *ptr) {
return CB_new_from_utf8(ptr, strlen(ptr));
}
PolyQuery*
-TestUtils_make_poly_query(uint32_t boolop, ...)
-{
+TestUtils_make_poly_query(uint32_t boolop, ...) {
va_list args;
Query *child;
PolyQuery *retval;
@@ -119,24 +114,22 @@ TestUtils_make_poly_query(uint32_t boolo
}
va_end(args);
- retval = boolop == BOOLOP_OR
- ? (PolyQuery*)ORQuery_new(children)
- : (PolyQuery*)ANDQuery_new(children);
+ retval = boolop == BOOLOP_OR
+ ? (PolyQuery*)ORQuery_new(children)
+ : (PolyQuery*)ANDQuery_new(children);
DECREF(children);
return retval;
}
TermQuery*
-TestUtils_make_term_query(const char *field, const char *term)
-{
+TestUtils_make_term_query(const char *field, const char *term) {
CharBuf *field_cb = (CharBuf*)ZCB_WRAP_STR(field, strlen(field));
CharBuf *term_cb = (CharBuf*)ZCB_WRAP_STR(term, strlen(term));
return TermQuery_new((CharBuf*)field_cb, (Obj*)term_cb);
}
PhraseQuery*
-TestUtils_make_phrase_query(const char *field, ...)
-{
+TestUtils_make_phrase_query(const char *field, ...) {
CharBuf *field_cb = (CharBuf*)ZCB_WRAP_STR(field, strlen(field));
va_list args;
VArray *terms = VA_new(0);
@@ -155,18 +148,16 @@ TestUtils_make_phrase_query(const char *
}
LeafQuery*
-TestUtils_make_leaf_query(const char *field, const char *term)
-{
+TestUtils_make_leaf_query(const char *field, const char *term) {
CharBuf *term_cb = (CharBuf*)ZCB_WRAP_STR(term, strlen(term));
- CharBuf *field_cb = field
- ? (CharBuf*)ZCB_WRAP_STR(field, strlen(field))
- : NULL;
+ CharBuf *field_cb = field
+ ? (CharBuf*)ZCB_WRAP_STR(field, strlen(field))
+ : NULL;
return LeafQuery_new(field_cb, term_cb);
}
NOTQuery*
-TestUtils_make_not_query(Query* negated_query)
-{
+TestUtils_make_not_query(Query* negated_query) {
NOTQuery *not_query = NOTQuery_new(negated_query);
DECREF(negated_query);
return not_query;
@@ -175,18 +166,16 @@ TestUtils_make_not_query(Query* negated_
RangeQuery*
TestUtils_make_range_query(const char *field, const char *lower_term,
const char *upper_term, bool_t include_lower,
- bool_t include_upper)
-{
+ bool_t include_upper) {
CharBuf *f = (CharBuf*)ZCB_WRAP_STR(field, strlen(field));
CharBuf *lterm = (CharBuf*)ZCB_WRAP_STR(lower_term, strlen(lower_term));
CharBuf *uterm = (CharBuf*)ZCB_WRAP_STR(upper_term, strlen(upper_term));
- return RangeQuery_new(f, (Obj*)lterm, (Obj*)uterm, include_lower,
- include_upper);
+ return RangeQuery_new(f, (Obj*)lterm, (Obj*)uterm, include_lower,
+ include_upper);
}
Obj*
-TestUtils_freeze_thaw(Obj *object)
-{
+TestUtils_freeze_thaw(Obj *object) {
if (object) {
RAMFile *ram_file = RAMFile_new(NULL, false);
OutStream *outstream = OutStream_open((Obj*)ram_file);
@@ -208,32 +197,31 @@ TestUtils_freeze_thaw(Obj *object)
void
TestUtils_test_analyzer(TestBatch *batch, Analyzer *analyzer, CharBuf *source,
- VArray *expected, char *message)
-{
- Token *seed = Token_new((char*)CB_Get_Ptr8(source),
- CB_Get_Size(source), 0, 0, 1.0f, 1);
+ VArray *expected, char *message) {
+ Token *seed = Token_new((char*)CB_Get_Ptr8(source), CB_Get_Size(source),
+ 0, 0, 1.0f, 1);
Inversion *starter = Inversion_new(seed);
Inversion *transformed = Analyzer_Transform(analyzer, starter);
VArray *got = VA_new(1);
Token *token;
while (NULL != (token = Inversion_Next(transformed))) {
- CharBuf *token_text
+ CharBuf *token_text
= CB_new_from_utf8(Token_Get_Text(token), Token_Get_Len(token));
VA_Push(got, (Obj*)token_text);
}
- TEST_TRUE(batch, VA_Equals(expected, (Obj*)got),
- "Transform(): %s", message);
+ TEST_TRUE(batch, VA_Equals(expected, (Obj*)got),
+ "Transform(): %s", message);
DECREF(transformed);
transformed = Analyzer_Transform_Text(analyzer, source);
VA_Clear(got);
while (NULL != (token = Inversion_Next(transformed))) {
- CharBuf *token_text
+ CharBuf *token_text
= CB_new_from_utf8(Token_Get_Text(token), Token_Get_Len(token));
VA_Push(got, (Obj*)token_text);
}
- TEST_TRUE(batch, VA_Equals(expected, (Obj*)got),
- "Transform_Text(): %s", message);
+ TEST_TRUE(batch, VA_Equals(expected, (Obj*)got),
+ "Transform_Text(): %s", message);
DECREF(transformed);
DECREF(got);
Modified: incubator/lucy/trunk/core/Lucy/Test/TestUtils.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/TestUtils.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/TestUtils.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Test/TestUtils.cfh Sun May 1 23:50:24 2011
@@ -20,7 +20,7 @@ inert class Lucy::Test::TestUtils {
/** Testing-only CharBuf factory which uses strlen().
*/
- inert incremented CharBuf*
+ inert incremented CharBuf*
get_cb(const char *utf8);
/** Return a random unsigned 64-bit integer.
@@ -83,9 +83,9 @@ inert class Lucy::Test::TestUtils {
make_not_query(Query *negated_query);
inert incremented RangeQuery*
- make_range_query(const char *field, const char *lower_term = NULL,
- const char *upper_term = NULL,
- bool_t include_lower = true,
+ make_range_query(const char *field, const char *lower_term = NULL,
+ const char *upper_term = NULL,
+ bool_t include_lower = true,
bool_t include_upper = true);
/** Return either an ORQuery or an ANDQuery depending on the value of
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.c Sun May 1 23:50:24 2011
@@ -25,15 +25,13 @@
#include "Lucy/Store/OutStream.h"
BBSortEx*
-BBSortEx_new(uint32_t mem_threshold, VArray *external)
-{
+BBSortEx_new(uint32_t mem_threshold, VArray *external) {
BBSortEx *self = (BBSortEx*)VTable_Make_Obj(BBSORTEX);
return BBSortEx_init(self, mem_threshold, external);
}
BBSortEx*
-BBSortEx_init(BBSortEx *self, uint32_t mem_threshold, VArray *external)
-{
+BBSortEx_init(BBSortEx *self, uint32_t mem_threshold, VArray *external) {
SortEx_init((SortExternal*)self, sizeof(Obj*));
self->external_tick = 0;
self->external = (VArray*)INCREF(external);
@@ -43,28 +41,26 @@ BBSortEx_init(BBSortEx *self, uint32_t m
}
void
-BBSortEx_destroy(BBSortEx *self)
-{
+BBSortEx_destroy(BBSortEx *self) {
DECREF(self->external);
SUPER_DESTROY(self, BBSORTEX);
}
void
-BBSortEx_clear_cache(BBSortEx *self)
-{
+BBSortEx_clear_cache(BBSortEx *self) {
Obj **const cache = (Obj**)self->cache;
for (uint32_t i = self->cache_tick, max = self->cache_max; i < max; i++) {
DECREF(cache[i]);
}
self->mem_consumed = 0;
- BBSortEx_clear_cache_t super_clear_cache = (BBSortEx_clear_cache_t)
- SUPER_METHOD(self->vtable, SortEx, Clear_Cache);
+ BBSortEx_clear_cache_t super_clear_cache
+ = (BBSortEx_clear_cache_t)SUPER_METHOD(
+ self->vtable, SortEx, Clear_Cache);
super_clear_cache(self);
}
void
-BBSortEx_feed(BBSortEx *self, void *data)
-{
+BBSortEx_feed(BBSortEx *self, void *data) {
SortEx_feed((SortExternal*)self, data);
// Flush() if necessary.
@@ -76,8 +72,7 @@ BBSortEx_feed(BBSortEx *self, void *data
}
void
-BBSortEx_flush(BBSortEx *self)
-{
+BBSortEx_flush(BBSortEx *self) {
uint32_t cache_count = self->cache_max - self->cache_tick;
Obj **cache = (Obj**)self->cache;
VArray *elems;
@@ -102,12 +97,11 @@ BBSortEx_flush(BBSortEx *self)
}
uint32_t
-BBSortEx_refill(BBSortEx *self)
-{
+BBSortEx_refill(BBSortEx *self) {
// Make sure cache is empty, then set cache tick vars.
if (self->cache_max - self->cache_tick > 0) {
THROW(ERR, "Refill called but cache contains %u32 items",
- self->cache_max - self->cache_tick);
+ self->cache_max - self->cache_tick);
}
self->cache_tick = 0;
self->cache_max = 0;
@@ -127,23 +121,22 @@ BBSortEx_refill(BBSortEx *self)
elem = (ByteBuf*)VA_Fetch(self->external, self->external_tick);
self->external_tick++;
// Should be + sizeof(ByteBuf), but that's ok.
- self->mem_consumed += BB_Get_Size(elem);
+ self->mem_consumed += BB_Get_Size(elem);
}
if (self->cache_max == self->cache_cap) {
BBSortEx_Grow_Cache(self,
- Memory_oversize(self->cache_max + 1, self->width));
+ Memory_oversize(self->cache_max + 1, self->width));
}
Obj **cache = (Obj**)self->cache;
- cache[ self->cache_max++ ] = INCREF(elem);
+ cache[self->cache_max++] = INCREF(elem);
}
return self->cache_max;
}
void
-BBSortEx_flip(BBSortEx *self)
-{
+BBSortEx_flip(BBSortEx *self) {
uint32_t i;
uint32_t run_mem_thresh = 65536;
@@ -168,10 +161,9 @@ BBSortEx_flip(BBSortEx *self)
}
int
-BBSortEx_compare(BBSortEx *self, void *va, void *vb)
-{
+BBSortEx_compare(BBSortEx *self, void *va, void *vb) {
UNUSED_VAR(self);
- return BB_compare( (ByteBuf**)va, (ByteBuf**)vb );
+ return BB_compare((ByteBuf**)va, (ByteBuf**)vb);
}
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/BBSortEx.cfh Sun May 1 23:50:24 2011
@@ -19,7 +19,7 @@ parcel Lucy;
/** SortExternal for ByteBufs.
*/
-class Lucy::Test::Util::BBSortEx
+class Lucy::Test::Util::BBSortEx
inherits Lucy::Util::SortExternal {
VArray *external;
@@ -30,7 +30,7 @@ class Lucy::Test::Util::BBSortEx
new(uint32_t mem_thresh = 0x1000000, VArray *external = NULL);
inert BBSortEx*
- init(BBSortEx *self, uint32_t mem_thresh = 0x1000000,
+ init(BBSortEx *self, uint32_t mem_thresh = 0x1000000,
VArray *external = NULL);
void
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestAtomic.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestAtomic.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestAtomic.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestAtomic.c Sun May 1 23:50:24 2011
@@ -21,36 +21,34 @@
#include "Lucy/Util/Atomic.h"
static void
-test_cas_ptr(TestBatch *batch)
-{
+test_cas_ptr(TestBatch *batch) {
int foo = 1;
int bar = 2;
int *foo_pointer = &foo;
int *bar_pointer = &bar;
int *target = NULL;
- TEST_TRUE(batch,
- Atomic_cas_ptr((void**)&target, NULL, foo_pointer),
- "cas_ptr returns true on success");
+ TEST_TRUE(batch,
+ Atomic_cas_ptr((void**)&target, NULL, foo_pointer),
+ "cas_ptr returns true on success");
TEST_TRUE(batch, target == foo_pointer, "cas_ptr sets target");
target = NULL;
- TEST_FALSE(batch,
- Atomic_cas_ptr((void**)&target, bar_pointer, foo_pointer),
- "cas_ptr returns false when it old_value doesn't match");
- TEST_TRUE(batch, target == NULL,
- "cas_ptr doesn't do anything to target when old_value doesn't match");
+ TEST_FALSE(batch,
+ Atomic_cas_ptr((void**)&target, bar_pointer, foo_pointer),
+ "cas_ptr returns false when it old_value doesn't match");
+ TEST_TRUE(batch, target == NULL,
+ "cas_ptr doesn't do anything to target when old_value doesn't match");
target = foo_pointer;
- TEST_TRUE(batch,
- Atomic_cas_ptr((void**)&target, foo_pointer, bar_pointer),
- "cas_ptr from one value to another");
+ TEST_TRUE(batch,
+ Atomic_cas_ptr((void**)&target, foo_pointer, bar_pointer),
+ "cas_ptr from one value to another");
TEST_TRUE(batch, target == bar_pointer, "cas_ptr sets target");
}
void
-TestAtomic_run_tests()
-{
+TestAtomic_run_tests() {
TestBatch *batch = TestBatch_new(6);
TestBatch_Plan(batch);
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestIndexFileNames.c Sun May 1 23:50:24 2011
@@ -21,11 +21,10 @@
#include "Lucy/Util/IndexFileNames.h"
static void
-test_local_part(TestBatch *batch)
-{
+test_local_part(TestBatch *batch) {
ZombieCharBuf *source = ZCB_BLANK();
ZombieCharBuf *got = ZCB_BLANK();
-
+
got = IxFileNames_local_part((CharBuf*)source, got);
TEST_TRUE(batch, ZCB_Equals(got, (Obj*)source), "simple name");
@@ -44,7 +43,7 @@ test_local_part(TestBatch *batch)
ZCB_Assign_Str(source, "foo/bar\\ ", 9);
got = IxFileNames_local_part((CharBuf*)source, got);
TEST_TRUE(batch, ZCB_Equals_Str(got, "bar\\ ", 5),
- "Include garbage like backslashes and spaces");
+ "Include garbage like backslashes and spaces");
ZCB_Assign_Str(source, "foo/bar/baz.txt", 15);
got = IxFileNames_local_part((CharBuf*)source, got);
@@ -52,30 +51,28 @@ test_local_part(TestBatch *batch)
}
static void
-test_extract_gen(TestBatch *batch)
-{
+test_extract_gen(TestBatch *batch) {
ZombieCharBuf *source = ZCB_WRAP_STR("", 0);
ZCB_Assign_Str(source, "seg_9", 5);
- TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
- "extract_gen");
+ TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
+ "extract_gen");
ZCB_Assign_Str(source, "seg_9/", 6);
- TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
- "deal with trailing slash");
+ TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
+ "deal with trailing slash");
ZCB_Assign_Str(source, "seg_9_8", 7);
- TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
- "Only go past first underscore");
+ TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 9,
+ "Only go past first underscore");
ZCB_Assign_Str(source, "snapshot_5.json", 15);
- TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 5,
- "Deal with file suffix");
+ TEST_TRUE(batch, IxFileNames_extract_gen((CharBuf*)source) == 5,
+ "Deal with file suffix");
}
void
-TestIxFileNames_run_tests()
-{
+TestIxFileNames_run_tests() {
TestBatch *batch = TestBatch_new(10);
TestBatch_Plan(batch);
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestJson.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestJson.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestJson.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestJson.c Sun May 1 23:50:24 2011
@@ -24,9 +24,8 @@
// Create a test data structure including at least one each of Hash, VArray,
// and CharBuf.
-static Obj*
-S_make_dump()
-{
+static Obj*
+S_make_dump() {
Hash *dump = Hash_new(0);
Hash_Store_Str(dump, "foo", 3, (Obj*)CB_newf("foo"));
Hash_Store_Str(dump, "stuff", 5, (Obj*)VA_new(0));
@@ -95,8 +94,7 @@ static char* quote_escapes_json[] = {
};
static void
-test_escapes(TestBatch *batch)
-{
+test_escapes(TestBatch *batch) {
CharBuf *string = CB_new(10);
CharBuf *json_wanted = CB_new(10);
@@ -110,10 +108,10 @@ test_escapes(TestBatch *batch)
CB_setf(json_wanted, "\"%s\"", escaped);
CB_Trim(json);
TEST_TRUE(batch, json != NULL && CB_Equals(json_wanted, (Obj*)json),
- "encode control escape: %s", escaped);
+ "encode control escape: %s", escaped);
- TEST_TRUE(batch, decoded != NULL && CB_Equals(string, (Obj*)decoded),
- "decode control escape: %s", escaped);
+ TEST_TRUE(batch, decoded != NULL && CB_Equals(string, (Obj*)decoded),
+ "decode control escape: %s", escaped);
DECREF(json);
DECREF(decoded);
@@ -129,10 +127,10 @@ test_escapes(TestBatch *batch)
CB_setf(json_wanted, "\"%s\"", escaped);
CB_Trim(json);
TEST_TRUE(batch, json != NULL && CB_Equals(json_wanted, (Obj*)json),
- "encode quote/backslash escapes: %s", source);
+ "encode quote/backslash escapes: %s", source);
- TEST_TRUE(batch, decoded != NULL && CB_Equals(string, (Obj*)decoded),
- "decode quote/backslash escapes: %s", source);
+ TEST_TRUE(batch, decoded != NULL && CB_Equals(string, (Obj*)decoded),
+ "decode quote/backslash escapes: %s", source);
DECREF(json);
DECREF(decoded);
@@ -143,8 +141,7 @@ test_escapes(TestBatch *batch)
}
static void
-test_numbers(TestBatch *batch)
-{
+test_numbers(TestBatch *batch) {
Integer64 *i64 = Int64_new(33);
CharBuf *json = Json_to_json((Obj*)i64);
CB_Trim(json);
@@ -169,62 +166,60 @@ test_numbers(TestBatch *batch)
}
static void
-test_to_and_from(TestBatch *batch)
-{
+test_to_and_from(TestBatch *batch) {
Obj *dump = S_make_dump();
CharBuf *json = Json_to_json(dump);
Obj *got = Json_from_json(json);
- TEST_TRUE(batch, got != NULL && Obj_Equals(dump, got),
- "Round trip through to_json and from_json");
+ TEST_TRUE(batch, got != NULL && Obj_Equals(dump, got),
+ "Round trip through to_json and from_json");
DECREF(dump);
DECREF(json);
DECREF(got);
}
static void
-test_spew_and_slurp(TestBatch *batch)
-{
+test_spew_and_slurp(TestBatch *batch) {
Obj *dump = S_make_dump();
Folder *folder = (Folder*)RAMFolder_new(NULL);
CharBuf *foo = (CharBuf*)ZCB_WRAP_STR("foo", 3);
bool_t result = Json_spew_json(dump, folder, foo);
TEST_TRUE(batch, result, "spew_json returns true on success");
- TEST_TRUE(batch, Folder_Exists(folder, foo),
- "spew_json wrote file");
+ TEST_TRUE(batch, Folder_Exists(folder, foo),
+ "spew_json wrote file");
Obj *got = Json_slurp_json(folder, foo);
- TEST_TRUE(batch, got && Obj_Equals(dump, got),
- "Round trip through spew_json and slurp_json");
+ TEST_TRUE(batch, got && Obj_Equals(dump, got),
+ "Round trip through spew_json and slurp_json");
DECREF(got);
Err_set_error(NULL);
result = Json_spew_json(dump, folder, foo);
TEST_FALSE(batch, result, "Can't spew_json when file exists");
- TEST_TRUE(batch, Err_get_error() != NULL,
- "Failed spew_json sets Err_error");
-
+ TEST_TRUE(batch, Err_get_error() != NULL,
+ "Failed spew_json sets Err_error");
+
Err_set_error(NULL);
CharBuf *bar = (CharBuf*)ZCB_WRAP_STR("bar", 3);
got = Json_slurp_json(folder, bar);
- TEST_TRUE(batch, got == NULL,
- "slurp_json returns NULL when file doesn't exist");
- TEST_TRUE(batch, Err_get_error() != NULL,
- "Failed slurp_json sets Err_error");
+ TEST_TRUE(batch, got == NULL,
+ "slurp_json returns NULL when file doesn't exist");
+ TEST_TRUE(batch, Err_get_error() != NULL,
+ "Failed slurp_json sets Err_error");
CharBuf *boffo = (CharBuf*)ZCB_WRAP_STR("boffo", 5);
{
- FileHandle *fh = Folder_Open_FileHandle(folder, boffo,
- FH_CREATE | FH_WRITE_ONLY );
+ FileHandle *fh
+ = Folder_Open_FileHandle(folder, boffo, FH_CREATE | FH_WRITE_ONLY);
FH_Write(fh, "garbage", 7);
DECREF(fh);
}
Err_set_error(NULL);
got = Json_slurp_json(folder, boffo);
- TEST_TRUE(batch, got == NULL,
- "slurp_json returns NULL when file doesn't contain valid JSON");
- TEST_TRUE(batch, Err_get_error() != NULL,
- "Failed slurp_json sets Err_error");
+ TEST_TRUE(batch, got == NULL,
+ "slurp_json returns NULL when file doesn't contain valid JSON");
+ TEST_TRUE(batch, Err_get_error() != NULL,
+ "Failed slurp_json sets Err_error");
DECREF(got);
DECREF(dump);
@@ -232,8 +227,7 @@ test_spew_and_slurp(TestBatch *batch)
}
void
-TestJson_run_tests()
-{
+TestJson_run_tests() {
TestBatch *batch = TestBatch_new(92);
// Liberalize for testing.
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestMemory.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestMemory.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestMemory.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestMemory.c Sun May 1 23:50:24 2011
@@ -22,8 +22,7 @@
#include "Lucy/Test/Util/TestMemory.h"
static void
-test_oversize__growth_rate(TestBatch *batch)
-{
+test_oversize__growth_rate(TestBatch *batch) {
bool_t success = true;
uint64_t size = 0;
double growth_count = 0;
@@ -34,7 +33,7 @@ test_oversize__growth_rate(TestBatch *ba
if (next_size < size) {
success = false;
FAIL(batch, "Asked for %" I64P ", got smaller amount %" I64P,
- size + 1, next_size);
+ size + 1, next_size);
break;
}
if (size > 0) {
@@ -43,8 +42,8 @@ test_oversize__growth_rate(TestBatch *ba
double sum = growth_rate + (growth_count - 1) * average_growth_rate;
average_growth_rate = sum / growth_count;
if (average_growth_rate < 1.1) {
- FAIL(batch, "Average growth rate dropped below 1.1x: %f",
- average_growth_rate);
+ FAIL(batch, "Average growth rate dropped below 1.1x: %f",
+ average_growth_rate);
success = false;
break;
}
@@ -53,47 +52,45 @@ test_oversize__growth_rate(TestBatch *ba
}
TEST_TRUE(batch, growth_count > 0, "Grew %f times", growth_count);
if (success) {
- TEST_TRUE(batch, average_growth_rate > 1.1,
- "Growth rate of oversize() averages above 1.1: %.3f",
- average_growth_rate);
+ TEST_TRUE(batch, average_growth_rate > 1.1,
+ "Growth rate of oversize() averages above 1.1: %.3f",
+ average_growth_rate);
}
for (int minimum = 1; minimum < 8; minimum++) {
uint64_t next_size = Memory_oversize(minimum, sizeof(void*));
double growth_rate = (double)next_size / (double)minimum;
- TEST_TRUE(batch, growth_rate > 1.2,
- "Growth rate is higher for smaller arrays (%d, %.3f)", minimum,
- growth_rate);
+ TEST_TRUE(batch, growth_rate > 1.2,
+ "Growth rate is higher for smaller arrays (%d, %.3f)", minimum,
+ growth_rate);
}
}
static void
-test_oversize__ceiling(TestBatch *batch)
-{
+test_oversize__ceiling(TestBatch *batch) {
for (int width = 0; width < 10; width++) {
size_t size = Memory_oversize(SIZE_MAX, width);
- TEST_TRUE(batch, size == SIZE_MAX,
- "Memory_oversize hits ceiling at SIZE_MAX (width %d)", width);
+ TEST_TRUE(batch, size == SIZE_MAX,
+ "Memory_oversize hits ceiling at SIZE_MAX (width %d)", width);
size = Memory_oversize(SIZE_MAX - 1, width);
- TEST_TRUE(batch, size == SIZE_MAX,
- "Memory_oversize hits ceiling at SIZE_MAX (width %d)", width);
+ TEST_TRUE(batch, size == SIZE_MAX,
+ "Memory_oversize hits ceiling at SIZE_MAX (width %d)", width);
}
}
static void
-test_oversize__rounding(TestBatch *batch)
-{
+test_oversize__rounding(TestBatch *batch) {
bool_t success = true;
int widths[] = { 1, 2, 4, 0 };
for (int width_tick = 0; widths[width_tick] != 0; width_tick++) {
int width = widths[width_tick];
- for (int i = 0; i < 25; i++) {
+ for (int i = 0; i < 25; i++) {
size_t size = Memory_oversize(i, width);
size_t bytes = size * width;
if (bytes % sizeof(void*) != 0) {
FAIL(batch, "Rounding failure for %d, width %d",
- i, width);
+ i, width);
success = false;
return;
}
@@ -103,8 +100,7 @@ test_oversize__rounding(TestBatch *batch
}
void
-TestMemory_run_tests()
-{
+TestMemory_run_tests() {
TestBatch *batch = TestBatch_new(30);
TestBatch_Plan(batch);
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestMemoryPool.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestMemoryPool.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestMemoryPool.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestMemoryPool.c Sun May 1 23:50:24 2011
@@ -23,8 +23,7 @@
#include "Lucy/Util/MemoryPool.h"
void
-TestMemPool_run_tests()
-{
+TestMemPool_run_tests() {
TestBatch *batch = TestBatch_new(4);
MemoryPool *mem_pool = MemPool_new(0);
MemoryPool *other = MemPool_new(0);
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestNumberUtils.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestNumberUtils.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestNumberUtils.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestNumberUtils.c Sun May 1 23:50:24 2011
@@ -25,8 +25,7 @@
#include "Lucy/Util/NumberUtils.h"
static void
-test_u1(TestBatch *batch)
-{
+test_u1(TestBatch *batch) {
size_t count = 64;
uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, 2);
size_t amount = count / 8;
@@ -36,8 +35,8 @@ test_u1(TestBatch *batch)
if (ints[i]) { NumUtil_u1set(bits, i); }
}
for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(batch, NumUtil_u1get(bits, i), (long)ints[i],
- "u1 set/get");
+ TEST_INT_EQ(batch, NumUtil_u1get(bits, i), (long)ints[i],
+ "u1 set/get");
}
for (size_t i = 0; i < count; i++) {
@@ -52,11 +51,10 @@ test_u1(TestBatch *batch)
}
static void
-test_u2(TestBatch *batch)
-{
+test_u2(TestBatch *batch) {
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));
+ 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]);
@@ -70,11 +68,10 @@ test_u2(TestBatch *batch)
}
static void
-test_u4(TestBatch *batch)
-{
+test_u4(TestBatch *batch) {
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));
+ 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]);
@@ -88,8 +85,7 @@ test_u4(TestBatch *batch)
}
static void
-test_c32(TestBatch *batch)
-{
+test_c32(TestBatch *batch) {
uint64_t mins[] = { 0, 0x4000 - 100, (uint32_t)I32_MAX - 100, U32_MAX - 10 };
uint64_t limits[] = { 500, 0x4000 + 100, (uint32_t)I32_MAX + 100, U32_MAX };
uint32_t set_num;
@@ -103,8 +99,8 @@ test_c32(TestBatch *batch)
for (set_num = 0; set_num < num_sets; set_num++) {
char *skip;
- ints = TestUtils_random_u64s(ints, count,
- mins[set_num], limits[set_num]);
+ 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);
@@ -112,31 +108,31 @@ test_c32(TestBatch *batch)
target = encoded;
skip = encoded;
for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(batch, NumUtil_decode_c32(&target), (long)ints[i],
- "c32 %lu", (long)ints[i]);
+ TEST_INT_EQ(batch, NumUtil_decode_c32(&target), (long)ints[i],
+ "c32 %lu", (long)ints[i]);
NumUtil_skip_cint(&skip);
if (target > limit) { THROW(ERR, "overrun"); }
}
- TEST_TRUE(batch, skip == target, "skip %lu == %lu",
- (unsigned long)skip, (unsigned long)target);
+ TEST_TRUE(batch, skip == target, "skip %lu == %lu",
+ (unsigned long)skip, (unsigned long)target);
target = encoded;
for (size_t i = 0; i < count; i++) {
NumUtil_encode_padded_c32((uint32_t)ints[i], &target);
}
- TEST_TRUE(batch, target == limit,
- "padded c32 uses 5 bytes (%lu == %lu)", (unsigned long)target,
- (unsigned long)limit);
+ TEST_TRUE(batch, target == limit,
+ "padded c32 uses 5 bytes (%lu == %lu)", (unsigned long)target,
+ (unsigned long)limit);
target = encoded;
skip = encoded;
for (size_t i = 0; i < count; i++) {
- TEST_INT_EQ(batch, NumUtil_decode_c32(&target), (long)ints[i],
- "padded c32 %lu", (long)ints[i]);
+ TEST_INT_EQ(batch, NumUtil_decode_c32(&target), (long)ints[i],
+ "padded c32 %lu", (long)ints[i]);
NumUtil_skip_cint(&skip);
if (target > limit) { THROW(ERR, "overrun"); }
}
- TEST_TRUE(batch, skip == target, "skip padded %lu == %lu",
- (unsigned long)skip, (unsigned long)target);
+ TEST_TRUE(batch, skip == target, "skip padded %lu == %lu",
+ (unsigned long)skip, (unsigned long)target);
}
target = encoded;
@@ -149,8 +145,7 @@ test_c32(TestBatch *batch)
}
static void
-test_c64(TestBatch *batch)
-{
+test_c64(TestBatch *batch) {
uint64_t mins[] = { 0, 0x4000 - 100, (uint64_t)U32_MAX - 100, U64_MAX - 10 };
uint64_t limits[] = { 500, 0x4000 + 100, (uint64_t)U32_MAX + 1000, U64_MAX };
uint32_t set_num;
@@ -164,8 +159,8 @@ test_c64(TestBatch *batch)
for (set_num = 0; set_num < num_sets; set_num++) {
char *skip;
- ints = TestUtils_random_u64s(ints, count,
- mins[set_num], limits[set_num]);
+ 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);
@@ -174,19 +169,19 @@ test_c64(TestBatch *batch)
skip = encoded;
for (size_t i = 0; i < count; i++) {
uint64_t got = NumUtil_decode_c64(&target);
- TEST_TRUE(batch, got == ints[i],
- "c64 %" U64P " == %" U64P, got, ints[i]);
+ TEST_TRUE(batch, got == ints[i],
+ "c64 %" U64P " == %" U64P, got, ints[i]);
if (target > limit) { THROW(ERR, "overrun"); }
NumUtil_skip_cint(&skip);
}
- TEST_TRUE(batch, skip == target, "skip %lu == %lu",
- (unsigned long)skip, (unsigned long)target);
+ TEST_TRUE(batch, skip == target, "skip %lu == %lu",
+ (unsigned long)skip, (unsigned long)target);
}
target = encoded;
NumUtil_encode_c64(U64_MAX, &target);
target = encoded;
- {
+ {
uint64_t got = NumUtil_decode_c64(&target);
TEST_TRUE(batch, got == U64_MAX, "c64 U64_MAX");
}
@@ -196,8 +191,7 @@ test_c64(TestBatch *batch)
}
static void
-test_bigend_u16(TestBatch *batch)
-{
+test_bigend_u16(TestBatch *batch) {
size_t count = 32;
uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, U16_MAX + 1);
size_t amount = (count + 1) * sizeof(uint16_t);
@@ -226,8 +220,7 @@ test_bigend_u16(TestBatch *batch)
}
static void
-test_bigend_u32(TestBatch *batch)
-{
+test_bigend_u32(TestBatch *batch) {
size_t count = 32;
uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, U64_C(1) + U32_MAX);
size_t amount = (count + 1) * sizeof(uint32_t);
@@ -256,8 +249,7 @@ test_bigend_u32(TestBatch *batch)
}
static void
-test_bigend_u64(TestBatch *batch)
-{
+test_bigend_u64(TestBatch *batch) {
size_t count = 32;
uint64_t *ints = TestUtils_random_u64s(NULL, count, 0, U64_MAX);
size_t amount = (count + 1) * sizeof(uint64_t);
@@ -286,8 +278,7 @@ test_bigend_u64(TestBatch *batch)
}
static void
-test_bigend_f32(TestBatch *batch)
-{
+test_bigend_f32(TestBatch *batch) {
float source[] = { -1.3f, 0.0f, 100.2f };
size_t count = 3;
size_t amount = (count + 1) * sizeof(float);
@@ -308,21 +299,20 @@ test_bigend_f32(TestBatch *batch)
target = encoded;
NumUtil_encode_bigend_f32(-2.0f, &target);
- TEST_INT_EQ(batch, (encoded[0] & 0x80), 0x80,
- "Truly big-endian (IEEE 754 sign bit set for negative number)");
- TEST_INT_EQ(batch, encoded[0], 0xC0,
- "IEEE 754 representation of -2.0f, byte 0");
+ TEST_INT_EQ(batch, (encoded[0] & 0x80), 0x80,
+ "Truly big-endian (IEEE 754 sign bit set for negative number)");
+ TEST_INT_EQ(batch, encoded[0], 0xC0,
+ "IEEE 754 representation of -2.0f, byte 0");
for (size_t i = 1; i < sizeof(float); i++) {
- TEST_INT_EQ(batch, encoded[i], 0,
- "IEEE 754 representation of -2.0f, byte %d", (int)i);
+ TEST_INT_EQ(batch, encoded[i], 0,
+ "IEEE 754 representation of -2.0f, byte %d", (int)i);
}
FREEMEM(allocated);
}
static void
-test_bigend_f64(TestBatch *batch)
-{
+test_bigend_f64(TestBatch *batch) {
double source[] = { -1.3, 0.0, 100.2 };
size_t count = 3;
size_t amount = (count + 1) * sizeof(double);
@@ -343,21 +333,20 @@ test_bigend_f64(TestBatch *batch)
target = encoded;
NumUtil_encode_bigend_f64(-2.0, &target);
- TEST_INT_EQ(batch, (encoded[0] & 0x80), 0x80,
- "Truly big-endian (IEEE 754 sign bit set for negative number)");
- TEST_INT_EQ(batch, encoded[0], 0xC0,
- "IEEE 754 representation of -2.0, byte 0");
+ TEST_INT_EQ(batch, (encoded[0] & 0x80), 0x80,
+ "Truly big-endian (IEEE 754 sign bit set for negative number)");
+ TEST_INT_EQ(batch, encoded[0], 0xC0,
+ "IEEE 754 representation of -2.0, byte 0");
for (size_t i = 1; i < sizeof(double); i++) {
- TEST_INT_EQ(batch, encoded[i], 0,
- "IEEE 754 representation of -2.0, byte %d", (int)i);
+ TEST_INT_EQ(batch, encoded[i], 0,
+ "IEEE 754 representation of -2.0, byte %d", (int)i);
}
FREEMEM(allocated);
}
void
-TestNumUtil_run_tests()
-{
+TestNumUtil_run_tests() {
TestBatch *batch = TestBatch_new(1196);
TestBatch_Plan(batch);
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestPriorityQueue.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestPriorityQueue.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestPriorityQueue.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestPriorityQueue.c Sun May 1 23:50:24 2011
@@ -22,16 +22,14 @@
#include "Lucy/Util/PriorityQueue.h"
NumPriorityQueue*
-NumPriQ_new(uint32_t max_size)
-{
- NumPriorityQueue *self
+NumPriQ_new(uint32_t max_size) {
+ NumPriorityQueue *self
= (NumPriorityQueue*)VTable_Make_Obj(NUMPRIORITYQUEUE);
return (NumPriorityQueue*)PriQ_init((PriorityQueue*)self, max_size);
}
bool_t
-NumPriQ_less_than(NumPriorityQueue *self, Obj *a, Obj *b)
-{
+NumPriQ_less_than(NumPriorityQueue *self, Obj *a, Obj *b) {
Float64 *num_a = (Float64*)a;
Float64 *num_b = (Float64*)b;
UNUSED_VAR(self);
@@ -39,14 +37,12 @@ NumPriQ_less_than(NumPriorityQueue *self
}
static void
-S_insert_num(NumPriorityQueue *pq, int32_t value)
-{
+S_insert_num(NumPriorityQueue *pq, int32_t value) {
NumPriQ_Insert(pq, (Obj*)Float64_new((double)value));
}
static int32_t
-S_pop_num(NumPriorityQueue *pq)
-{
+S_pop_num(NumPriorityQueue *pq) {
Float64 *num = (Float64*)NumPriQ_Pop(pq);
int32_t retval;
if (!num) { THROW(ERR, "Queue is empty"); }
@@ -56,8 +52,7 @@ S_pop_num(NumPriorityQueue *pq)
}
static void
-test_Peek_and_Pop_All(TestBatch *batch)
-{
+test_Peek_and_Pop_All(TestBatch *batch) {
NumPriorityQueue *pq = NumPriQ_new(5);
Float64 *val;
@@ -67,8 +62,8 @@ test_Peek_and_Pop_All(TestBatch *batch)
S_insert_num(pq, 20);
S_insert_num(pq, 10);
val = (Float64*)CERTIFY(NumPriQ_Peek(pq), FLOAT64);
- TEST_INT_EQ(batch, (long)Float64_Get_Value(val), 1,
- "peek at the least item in the queue" );
+ TEST_INT_EQ(batch, (long)Float64_Get_Value(val), 1,
+ "peek at the least item in the queue");
{
VArray *got = NumPriQ_Pop_All(pq);
@@ -90,8 +85,7 @@ test_Peek_and_Pop_All(TestBatch *batch)
}
static void
-test_Insert_and_Pop(TestBatch *batch)
-{
+test_Insert_and_Pop(TestBatch *batch) {
NumPriorityQueue *pq = NumPriQ_new(5);
S_insert_num(pq, 3);
@@ -100,21 +94,20 @@ test_Insert_and_Pop(TestBatch *batch)
S_insert_num(pq, 20);
S_insert_num(pq, 10);
- TEST_INT_EQ(batch, S_pop_num(pq), 1, "Pop");
- TEST_INT_EQ(batch, S_pop_num(pq), 2, "Pop");
- TEST_INT_EQ(batch, S_pop_num(pq), 3, "Pop");
- TEST_INT_EQ(batch, S_pop_num(pq), 10, "Pop");
+ TEST_INT_EQ(batch, S_pop_num(pq), 1, "Pop");
+ TEST_INT_EQ(batch, S_pop_num(pq), 2, "Pop");
+ TEST_INT_EQ(batch, S_pop_num(pq), 3, "Pop");
+ TEST_INT_EQ(batch, S_pop_num(pq), 10, "Pop");
S_insert_num(pq, 7);
- TEST_INT_EQ(batch, S_pop_num(pq), 7,
- "Insert after Pop still sorts correctly");
+ TEST_INT_EQ(batch, S_pop_num(pq), 7,
+ "Insert after Pop still sorts correctly");
DECREF(pq);
}
static void
-test_discard(TestBatch *batch)
-{
+test_discard(TestBatch *batch) {
int32_t i;
NumPriorityQueue *pq = NumPriQ_new(5);
@@ -123,31 +116,30 @@ test_discard(TestBatch *batch)
for (i = 1590; i <= 1600; i++) { S_insert_num(pq, i); }
S_insert_num(pq, 5);
- TEST_INT_EQ(batch, S_pop_num(pq), 1596, "discard waste");
- TEST_INT_EQ(batch, S_pop_num(pq), 1597, "discard waste");
- TEST_INT_EQ(batch, S_pop_num(pq), 1598, "discard waste");
- TEST_INT_EQ(batch, S_pop_num(pq), 1599, "discard waste");
- TEST_INT_EQ(batch, S_pop_num(pq), 1600, "discard waste");
+ TEST_INT_EQ(batch, S_pop_num(pq), 1596, "discard waste");
+ TEST_INT_EQ(batch, S_pop_num(pq), 1597, "discard waste");
+ TEST_INT_EQ(batch, S_pop_num(pq), 1598, "discard waste");
+ TEST_INT_EQ(batch, S_pop_num(pq), 1599, "discard waste");
+ TEST_INT_EQ(batch, S_pop_num(pq), 1600, "discard waste");
DECREF(pq);
}
static void
-test_random_insertion(TestBatch *batch)
-{
+test_random_insertion(TestBatch *batch) {
int i;
int shuffled[64];
NumPriorityQueue *pq = NumPriQ_new(64);
for (i = 0; i < 64; i++) { shuffled[i] = i; }
- for (i = 0; i < 64; i++) {
+ for (i = 0; i < 64; i++) {
int shuffle_pos = rand() % 64;
int temp = shuffled[shuffle_pos];
shuffled[shuffle_pos] = shuffled[i];
- shuffled[i] = temp;
+ shuffled[i] = temp;
}
for (i = 0; i < 64; i++) { S_insert_num(pq, shuffled[i]); }
- for (i = 0; i < 64; i++) {
+ for (i = 0; i < 64; i++) {
if (S_pop_num(pq) != i) { break; }
}
TEST_INT_EQ(batch, i, 64, "random insertion");
@@ -156,9 +148,8 @@ test_random_insertion(TestBatch *batch)
}
void
-TestPriQ_run_tests()
-{
- TestBatch *batch = TestBatch_new(17);
+TestPriQ_run_tests() {
+ TestBatch *batch = TestBatch_new(17);
TestBatch_Plan(batch);
Modified: incubator/lucy/trunk/core/Lucy/Test/Util/TestStringHelper.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Util/TestStringHelper.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Util/TestStringHelper.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Util/TestStringHelper.c Sun May 1 23:50:24 2011
@@ -21,8 +21,7 @@
#include "Lucy/Util/StringHelper.h"
static void
-test_overlap(TestBatch *batch)
-{
+test_overlap(TestBatch *batch) {
int32_t result;
result = StrHelp_overlap("", "", 0, 0);
TEST_INT_EQ(batch, result, 0, "two empty strings");
@@ -40,8 +39,7 @@ test_overlap(TestBatch *batch)
static void
-test_to_base36(TestBatch *batch)
-{
+test_to_base36(TestBatch *batch) {
char buffer[StrHelp_MAX_BASE36_BYTES];
StrHelp_to_base36(U64_MAX, buffer);
TEST_STR_EQ(batch, "3w5e11264sgsf", buffer, "base36 U64_MAX");
@@ -51,29 +49,27 @@ test_to_base36(TestBatch *batch)
}
static void
-S_round_trip_utf8_code_point(TestBatch *batch, uint32_t code_point)
-{
+S_round_trip_utf8_code_point(TestBatch *batch, uint32_t code_point) {
char buffer[4];
uint32_t len = StrHelp_encode_utf8_char(code_point, buffer);
char *start = buffer;
char *end = start + len;
- TEST_TRUE(batch, StrHelp_utf8_valid(buffer, len), "Valid UTF-8 for %lu",
- (unsigned long)code_point);
- TEST_INT_EQ(batch, len, StrHelp_UTF8_COUNT[(unsigned char)buffer[0]],
- "length returned for %lu", (unsigned long)code_point);
- TEST_TRUE(batch, StrHelp_back_utf8_char(end, start) == start,
- "back_utf8_char for %lu", (unsigned long)code_point);
+ TEST_TRUE(batch, StrHelp_utf8_valid(buffer, len), "Valid UTF-8 for %lu",
+ (unsigned long)code_point);
+ TEST_INT_EQ(batch, len, StrHelp_UTF8_COUNT[(unsigned char)buffer[0]],
+ "length returned for %lu", (unsigned long)code_point);
+ TEST_TRUE(batch, StrHelp_back_utf8_char(end, start) == start,
+ "back_utf8_char for %lu", (unsigned long)code_point);
TEST_INT_EQ(batch, StrHelp_decode_utf8_char(buffer), code_point,
- "round trip encode and decode for %lu", (unsigned long)code_point);
+ "round trip encode and decode for %lu", (unsigned long)code_point);
}
static void
-test_utf8_round_trip(TestBatch *batch)
-{
- uint32_t code_points[] = {
- 0,
+test_utf8_round_trip(TestBatch *batch) {
+ uint32_t code_points[] = {
+ 0,
0xA, // newline
- 'a',
+ 'a',
128, // two-byte
0x263A, // smiley (three-byte)
0x10FFFF, // Max legal code point (four-byte).
@@ -86,37 +82,34 @@ test_utf8_round_trip(TestBatch *batch)
}
static void
-test_is_whitespace(TestBatch *batch)
-{
+test_is_whitespace(TestBatch *batch) {
TEST_TRUE(batch, StrHelp_is_whitespace(' '), "space is whitespace");
TEST_TRUE(batch, StrHelp_is_whitespace('\n'), "newline is whitespace");
TEST_TRUE(batch, StrHelp_is_whitespace('\t'), "tab is whitespace");
- TEST_TRUE(batch, StrHelp_is_whitespace('\v'),
- "vertical tab is whitespace");
- TEST_TRUE(batch, StrHelp_is_whitespace(0x180E),
- "Mongolian vowel separator is whitespace");
+ TEST_TRUE(batch, StrHelp_is_whitespace('\v'),
+ "vertical tab is whitespace");
+ TEST_TRUE(batch, StrHelp_is_whitespace(0x180E),
+ "Mongolian vowel separator is whitespace");
TEST_FALSE(batch, StrHelp_is_whitespace('a'), "'a' isn't whitespace");
TEST_FALSE(batch, StrHelp_is_whitespace(0), "NULL isn't whitespace");
- TEST_FALSE(batch, StrHelp_is_whitespace(0x263A),
- "Smiley isn't whitespace");
+ TEST_FALSE(batch, StrHelp_is_whitespace(0x263A),
+ "Smiley isn't whitespace");
}
static void
-test_back_utf8_char(TestBatch *batch)
-{
+test_back_utf8_char(TestBatch *batch) {
char buffer[4];
char *buf = buffer + 1;
uint32_t len = StrHelp_encode_utf8_char(0x263A, buffer);
char *end = buffer + len;
TEST_TRUE(batch, StrHelp_back_utf8_char(end, buffer) == buffer,
- "back_utf8_char");
+ "back_utf8_char");
TEST_TRUE(batch, StrHelp_back_utf8_char(end, buf) == NULL,
- "back_utf8_char returns NULL rather than back up beyond start");
+ "back_utf8_char returns NULL rather than back up beyond start");
}
void
-TestStrHelp_run_tests()
-{
+TestStrHelp_run_tests() {
TestBatch *batch = TestBatch_new(43);
TestBatch_Plan(batch);
Modified: incubator/lucy/trunk/core/Lucy/Util/Atomic.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Atomic.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Atomic.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Atomic.c Sun May 1 23:50:24 2011
@@ -23,11 +23,10 @@
#include <windows.h>
chy_bool_t
-lucy_Atomic_wrapped_cas_ptr(void *volatile *target, void *old_value,
- void *new_value)
-{
- return InterlockedCompareExchangePointer(target, new_value, old_value)
- == old_value;
+lucy_Atomic_wrapped_cas_ptr(void *volatile *target, void *old_value,
+ void *new_value) {
+ return InterlockedCompareExchangePointer(target, new_value, old_value)
+ == old_value;
}
/************************** Fall back to ptheads ***************************/
Modified: incubator/lucy/trunk/core/Lucy/Util/Atomic.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Atomic.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Atomic.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Atomic.cfh Sun May 1 23:50:24 2011
@@ -34,8 +34,7 @@ lucy_Atomic_cas_ptr(void *volatile *targ
#include <libkern/OSAtomic.h>
static CHY_INLINE chy_bool_t
-lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value)
-{
+lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value) {
return OSAtomicCompareAndSwapPtr(old_value, new_value, target);
}
@@ -43,12 +42,11 @@ lucy_Atomic_cas_ptr(void *volatile *targ
#elif defined(CHY_HAS_WINDOWS_H)
chy_bool_t
-lucy_Atomic_wrapped_cas_ptr(void *volatile *target, void *old_value,
+lucy_Atomic_wrapped_cas_ptr(void *volatile *target, void *old_value,
void *new_value);
static CHY_INLINE chy_bool_t
-lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value)
-{
+lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value) {
return lucy_Atomic_wrapped_cas_ptr(target, old_value, new_value);
}
@@ -57,8 +55,7 @@ lucy_Atomic_cas_ptr(void *volatile *targ
#include <sys/atomic.h>
static CHY_INLINE chy_bool_t
-lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value)
-{
+lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value) {
return atomic_cas_ptr(target, old_value, new_value) == old_value;
}
@@ -69,8 +66,7 @@ lucy_Atomic_cas_ptr(void *volatile *targ
extern pthread_mutex_t lucy_Atomic_mutex;
static CHY_INLINE chy_bool_t
-lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value)
-{
+lucy_Atomic_cas_ptr(void *volatile *target, void *old_value, void *new_value) {
pthread_mutex_lock(&lucy_Atomic_mutex);
if (*target == old_value) {
*target = new_value;
Modified: incubator/lucy/trunk/core/Lucy/Util/Debug.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Debug.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Debug.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Debug.c Sun May 1 23:50:24 2011
@@ -31,15 +31,14 @@ int32_t Debug_num_globals = 0;
#include <string.h>
#include <stdlib.h>
-static char env_cache_buf[256];
-static char *env_cache = NULL;
-static char *env_cache_limit = NULL;
-static int env_cache_is_current = 0;
+static char env_cache_buf[256];
+static char *env_cache = NULL;
+static char *env_cache_limit = NULL;
+static int env_cache_is_current = 0;
// Cache the system call to getenv.
static void
-S_cache_debug_env_var(char *override)
-{
+S_cache_debug_env_var(char *override) {
const char *debug_env = override ? override : getenv("DEBUG");
if (debug_env != NULL) {
size_t len = strlen(debug_env);
@@ -54,9 +53,8 @@ S_cache_debug_env_var(char *override)
}
void
-Debug_print_mess(const char *file, int line, const char *func,
- const char *pat, ...)
-{
+Debug_print_mess(const char *file, int line, const char *func,
+ const char *pat, ...) {
va_list args;
fprintf(stderr, "%s:%d %s(): ", file, line, func);
va_start(args, pat);
@@ -65,9 +63,8 @@ Debug_print_mess(const char *file, int l
fprintf(stderr, "\n");
}
-int
-Debug_debug_should_print(const char *path, const char *func)
-{
+int
+Debug_debug_should_print(const char *path, const char *func) {
if (!env_cache_is_current) {
S_cache_debug_env_var(NULL);
}
@@ -85,7 +82,7 @@ Debug_debug_should_print(const char *pat
// Use just file name if given path.
if (file) file++;
else file = path;
-
+
// Split criteria on commas. Bail when we run out of critieria.
for (test = env_cache; test != NULL; test = next) {
const char *last_char;
@@ -96,17 +93,17 @@ Debug_debug_should_print(const char *pat
// Find end of criteria or end of string.
next = strchr(test, ',');
- last_char = next ? next - 1 : env_cache_limit - 1;
+ last_char = next ? next - 1 : env_cache_limit - 1;
while (last_char > test && isspace(*last_char)) last_char--;
if (*last_char == '*') {
const int len = last_char - test;
- if (! strncmp(test, file, len)) return 1;
- if (! strncmp(test, func, len)) return 1;
+ if (!strncmp(test, file, len)) return 1;
+ if (!strncmp(test, func, len)) return 1;
}
else {
- if (! strncmp(test, file, filename_len)) return 1;
- if (! strncmp(test, func, funcname_len)) return 1;
+ if (!strncmp(test, file, filename_len)) return 1;
+ if (!strncmp(test, func, funcname_len)) return 1;
}
}
@@ -116,16 +113,14 @@ Debug_debug_should_print(const char *pat
}
void
-Debug_set_env_cache(char *override)
-{
+Debug_set_env_cache(char *override) {
S_cache_debug_env_var(override);
}
#else // DEBUG
void
-Debug_set_env_cache(char *override)
-{
+Debug_set_env_cache(char *override) {
(void)override;
}
Modified: incubator/lucy/trunk/core/Lucy/Util/Debug.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Debug.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Debug.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Debug.cfh Sun May 1 23:50:24 2011
@@ -36,12 +36,12 @@ inert class Lucy::Util::Debug {
/** Private function, used only by the DEBUG macros.
*/
inert void
- print_mess(const char *file, int line, const char *func,
+ print_mess(const char *file, int line, const char *func,
const char *pat, ...);
/** Private function, used only by the DEBUG macros.
*/
- inert int
+ inert int
debug_should_print(const char *path, const char *func);
/** Force override in cached value of LUCY_DEBUG environment variable.
@@ -94,7 +94,7 @@ __C__
/** Conditionally print debug statement depending on LUCY_DEBUG env variable.
*/
#define LUCY_DEBUG(args...) \
- LUCY_DEBUG_DO(LUCY_DEBUG_PRINT(args));
+ LUCY_DEBUG_DO(LUCY_DEBUG_PRINT(args));
/** Abort on error if test fails.
*
@@ -106,7 +106,7 @@ __C__
LUCY_DEBUG_PRINT("ASSERT FAILED (" #test ")\n" args); \
abort(); \
} \
- } while (0)
+ } while (0)
#elif defined(CHY_HAS_GNUC_VARIADIC_MACROS) // not LUCY_DEBUG
Modified: incubator/lucy/trunk/core/Lucy/Util/Freezer.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Freezer.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Freezer.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Freezer.c Sun May 1 23:50:24 2011
@@ -22,15 +22,13 @@
#include "Lucy/Store/OutStream.h"
void
-Freezer_freeze(Obj *obj, OutStream *outstream)
-{
+Freezer_freeze(Obj *obj, OutStream *outstream) {
CB_Serialize(Obj_Get_Class_Name(obj), outstream);
Obj_Serialize(obj, outstream);
}
Obj*
-Freezer_thaw(InStream *instream)
-{
+Freezer_thaw(InStream *instream) {
CharBuf *class_name = CB_deserialize(NULL, instream);
VTable *vtable = VTable_singleton(class_name, NULL);
Obj *blank = VTable_Make_Obj(vtable);
Modified: incubator/lucy/trunk/core/Lucy/Util/Freezer.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Freezer.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Freezer.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Freezer.cfh Sun May 1 23:50:24 2011
@@ -37,7 +37,7 @@ __C__
lucy_Freezer_thaw(instream)
#ifdef LUCY_USE_SHORT_NAMES
- #define FREEZE LUCY_FREEZE
+ #define FREEZE LUCY_FREEZE
#define THAW LUCY_THAW
#endif
__END_C__
Modified: incubator/lucy/trunk/core/Lucy/Util/IndexFileNames.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/IndexFileNames.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/IndexFileNames.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/IndexFileNames.c Sun May 1 23:50:24 2011
@@ -23,8 +23,7 @@
#include "Lucy/Util/StringHelper.h"
CharBuf*
-IxFileNames_latest_snapshot(Folder *folder)
-{
+IxFileNames_latest_snapshot(Folder *folder) {
DirHandle *dh = Folder_Open_Dir(folder, NULL);
CharBuf *entry = dh ? DH_Get_Entry(dh) : NULL;
CharBuf *retval = NULL;
@@ -33,9 +32,9 @@ IxFileNames_latest_snapshot(Folder *fold
if (!dh) { RETHROW(INCREF(Err_get_error())); }
while (DH_Next(dh)) {
- if ( CB_Starts_With_Str(entry, "snapshot_", 9)
+ if (CB_Starts_With_Str(entry, "snapshot_", 9)
&& CB_Ends_With_Str(entry, ".json", 5)
- ) {
+ ) {
uint64_t gen = IxFileNames_extract_gen(entry);
if (gen > latest_gen) {
latest_gen = gen;
@@ -50,8 +49,7 @@ IxFileNames_latest_snapshot(Folder *fold
}
uint64_t
-IxFileNames_extract_gen(const CharBuf *name)
-{
+IxFileNames_extract_gen(const CharBuf *name) {
ZombieCharBuf *num_string = ZCB_WRAP(name);
// Advance past first underscore. Bail if we run out of string or if we
@@ -66,8 +64,7 @@ IxFileNames_extract_gen(const CharBuf *n
}
ZombieCharBuf*
-IxFileNames_local_part(const CharBuf *path, ZombieCharBuf *target)
-{
+IxFileNames_local_part(const CharBuf *path, ZombieCharBuf *target) {
ZombieCharBuf *scratch = ZCB_WRAP(path);
size_t local_part_start = CB_Length(path);
uint32_t code_point;
Modified: incubator/lucy/trunk/core/Lucy/Util/Json.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Json.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Json.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Json.cfh Sun May 1 23:50:24 2011
@@ -24,13 +24,13 @@ class Lucy::Util::Json inherits Lucy::Ob
/** Encode <code>dump</code> as JSON.
*/
- inert incremented CharBuf*
+ inert incremented CharBuf*
to_json(Obj *dump);
/** Decode the supplied JSON and return a data structure made
* of Hashes, VArrays, and CharBufs.
*/
- inert incremented Obj*
+ inert incremented Obj*
from_json(CharBuf *json);
/** Encode <code>dump</code> as JSON and attempt to write to the indicated
@@ -45,7 +45,7 @@ class Lucy::Util::Json inherits Lucy::Ob
* Err_error if the file can't be can't be opened or if the file doesn't
* contain valid JSON.
*/
- inert incremented nullable Obj*
+ inert incremented nullable Obj*
slurp_json(Folder *folder, const CharBuf *path);
/** Allow the encoder to output strings, etc, instead of throwing an error
Modified: incubator/lucy/trunk/core/Lucy/Util/Memory.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Memory.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Memory.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Memory.c Sun May 1 23:50:24 2011
@@ -22,8 +22,7 @@
#include "Lucy/Util/Memory.h"
void*
-Memory_wrapped_malloc(size_t count)
-{
+Memory_wrapped_malloc(size_t count) {
void *pointer = malloc(count);
if (pointer == NULL && count != 0) {
fprintf(stderr, "Can't malloc %" U64P " bytes.\n", (uint64_t)count);
@@ -33,20 +32,18 @@ Memory_wrapped_malloc(size_t count)
}
void*
-Memory_wrapped_calloc(size_t count, size_t size)
-{
+Memory_wrapped_calloc(size_t count, size_t size) {
void *pointer = calloc(count, size);
if (pointer == NULL && count != 0) {
- fprintf(stderr, "Can't calloc %" U64P " elements of size %" U64P ".\n",
- (uint64_t)count, (uint64_t)size);
+ fprintf(stderr, "Can't calloc %" U64P " elements of size %" U64P ".\n",
+ (uint64_t)count, (uint64_t)size);
exit(1);
}
return pointer;
}
void*
-Memory_wrapped_realloc(void *ptr, size_t size)
-{
+Memory_wrapped_realloc(void *ptr, size_t size) {
void *pointer = realloc(ptr, size);
if (pointer == NULL && size != 0) {
fprintf(stderr, "Can't realloc %" U64P " bytes.\n", (uint64_t)size);
@@ -56,8 +53,7 @@ Memory_wrapped_realloc(void *ptr, size_t
}
void
-Memory_wrapped_free(void *ptr)
-{
+Memory_wrapped_free(void *ptr) {
free(ptr);
}
@@ -66,8 +62,7 @@ Memory_wrapped_free(void *ptr)
#endif
size_t
-Memory_oversize(size_t minimum, size_t width)
-{
+Memory_oversize(size_t minimum, size_t width) {
// For larger arrays, grow by an excess of 1/8; grow faster when the array
// is small.
size_t extra = minimum / 8;
@@ -77,25 +72,37 @@ Memory_oversize(size_t minimum, size_t w
size_t amount = minimum + extra;
// Detect wraparound and return SIZE_MAX instead.
- if (amount + 7 < minimum) {
+ if (amount + 7 < minimum) {
return SIZE_MAX;
}
// Round up for small widths so that the number of bytes requested will be
// a multiple of the machine's word size.
if (sizeof(size_t) == 8) { // 64-bit
- switch(width) {
- case 1: amount = (amount + 7) & CHY_I64_C(0xFFFFFFFFFFFFFFF8); break;
- case 2: amount = (amount + 3) & CHY_I64_C(0xFFFFFFFFFFFFFFFC); break;
- case 4: amount = (amount + 1) & CHY_I64_C(0xFFFFFFFFFFFFFFFE); break;
- default: break;
+ switch (width) {
+ case 1:
+ amount = (amount + 7) & CHY_I64_C(0xFFFFFFFFFFFFFFF8);
+ break;
+ case 2:
+ amount = (amount + 3) & CHY_I64_C(0xFFFFFFFFFFFFFFFC);
+ break;
+ case 4:
+ amount = (amount + 1) & CHY_I64_C(0xFFFFFFFFFFFFFFFE);
+ break;
+ default:
+ break;
}
}
else { // 32-bit
- switch(width) {
- case 1: amount = (amount + 3) & ((size_t)0xFFFFFFFC); break;
- case 2: amount = (amount + 1) & ((size_t)0xFFFFFFFE); break;
- default: break;
+ switch (width) {
+ case 1:
+ amount = (amount + 3) & ((size_t)0xFFFFFFFC);
+ break;
+ case 2:
+ amount = (amount + 1) & ((size_t)0xFFFFFFFE);
+ break;
+ default:
+ break;
}
}
Modified: incubator/lucy/trunk/core/Lucy/Util/Memory.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/Memory.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/Memory.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Util/Memory.cfh Sun May 1 23:50:24 2011
@@ -50,7 +50,7 @@ inert class Lucy::Util::Memory {
* @param minimum The minimum number of array elements.
* @param width The size of each array element in bytes.
*/
- inert size_t
+ inert size_t
oversize(size_t minimum, size_t width);
}
Modified: incubator/lucy/trunk/core/Lucy/Util/MemoryPool.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/MemoryPool.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/MemoryPool.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/MemoryPool.c Sun May 1 23:50:24 2011
@@ -35,35 +35,31 @@ S_init_arena(MemoryPool *self, size_t am
} while (0)
MemoryPool*
-MemPool_new(uint32_t arena_size)
-{
+MemPool_new(uint32_t arena_size) {
MemoryPool *self = (MemoryPool*)VTable_Make_Obj(MEMORYPOOL);
return MemPool_init(self, arena_size);
}
MemoryPool*
-MemPool_init(MemoryPool *self, uint32_t arena_size)
-{
+MemPool_init(MemoryPool *self, uint32_t arena_size) {
self->arena_size = arena_size == 0 ? DEFAULT_BUF_SIZE : arena_size;
self->arenas = VA_new(16);
self->tick = -1;
self->buf = NULL;
self->limit = NULL;
self->consumed = 0;
-
+
return self;
}
void
-MemPool_destroy(MemoryPool *self)
-{
+MemPool_destroy(MemoryPool *self) {
DECREF(self->arenas);
SUPER_DESTROY(self, MEMORYPOOL);
}
static void
-S_init_arena(MemoryPool *self, size_t amount)
-{
+S_init_arena(MemoryPool *self, size_t amount) {
ByteBuf *bb;
int32_t i;
@@ -80,9 +76,9 @@ S_init_arena(MemoryPool *self, size_t am
}
else {
// In add mode, get more mem from system.
- size_t buf_size = (amount + 1) > self->arena_size
- ? (amount + 1)
- : self->arena_size;
+ size_t buf_size = (amount + 1) > self->arena_size
+ ? (amount + 1)
+ : self->arena_size;
char *ptr = (char*)MALLOCATE(buf_size);
bb = BB_new_steal_bytes(ptr, buf_size - 1, buf_size);
VA_Push(self->arenas, (Obj*)bb);
@@ -100,11 +96,12 @@ S_init_arena(MemoryPool *self, size_t am
}
size_t
-MemPool_get_consumed(MemoryPool *self) { return self->consumed; }
+MemPool_get_consumed(MemoryPool *self) {
+ return self->consumed;
+}
void*
-MemPool_grab(MemoryPool *self, size_t amount)
-{
+MemPool_grab(MemoryPool *self, size_t amount) {
INCREASE_TO_WORD_MULTIPLE(amount);
self->last_buf = self->buf;
@@ -124,8 +121,7 @@ MemPool_grab(MemoryPool *self, size_t am
}
void
-MemPool_resize(MemoryPool *self, void *ptr, size_t new_amount)
-{
+MemPool_resize(MemoryPool *self, void *ptr, size_t new_amount) {
const size_t last_amount = self->buf - self->last_buf;
INCREASE_TO_WORD_MULTIPLE(new_amount);
@@ -139,15 +135,14 @@ MemPool_resize(MemoryPool *self, void *p
self->consumed -= difference;
}
else {
- THROW(ERR, "Can't resize to greater amount: %u64 > %u64",
- (uint64_t)new_amount, (uint64_t)last_amount);
+ THROW(ERR, "Can't resize to greater amount: %u64 > %u64",
+ (uint64_t)new_amount, (uint64_t)last_amount);
}
}
}
void
-MemPool_release_all(MemoryPool *self)
-{
+MemPool_release_all(MemoryPool *self) {
self->tick = -1;
self->buf = NULL;
self->last_buf = NULL;
@@ -165,7 +160,7 @@ MemPool_eat(MemoryPool *self, MemoryPool
for (i = 0; i <= other->tick; i++) {
ByteBuf *arena = (ByteBuf*)VA_Shift(other->arenas);
// Maybe displace existing arena.
- VA_Store(self->arenas, i, (Obj*)arena);
+ VA_Store(self->arenas, i, (Obj*)arena);
}
self->tick = other->tick;
self->last_buf = other->last_buf;
Modified: incubator/lucy/trunk/core/Lucy/Util/NumberUtils.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/NumberUtils.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/NumberUtils.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Util/NumberUtils.cfh Sun May 1 23:50:24 2011
@@ -21,14 +21,14 @@ parcel Lucy;
* Provide utilities for dealing with endian issues, sub-byte-width arrays,
* compressed integers, and so on.
*/
-inert class Lucy::Util::NumberUtils cnick NumUtil {
+inert class Lucy::Util::NumberUtils cnick 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.
*/
@@ -65,25 +65,25 @@ inert class Lucy::Util::NumberUtils cnic
/** Encode a 32-bit floating point number as 4 bytes in the buffer
* provided, using big-endian byte order.
*/
- inert inline void
+ 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
+ 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
+ inert inline float
decode_bigend_f32(void *source);
/** Interpret a sequence of bytes as a 64-bit float stored in big-endian
* byte order.
*/
- inert inline double
+ inert inline double
decode_bigend_f64(void *source);
/** Encode a C32 at the space pointed to by <code>dest</code>. As a side
@@ -124,7 +124,7 @@ inert class Lucy::Util::NumberUtils cnic
/** Advance <code>source</code> past one encoded C32 or C64.
*/
- inert inline void
+ inert inline void
skip_cint(char **source);
/** Interpret <code>array</code> as an array of bits; return true if the
@@ -136,13 +136,13 @@ inert class Lucy::Util::NumberUtils cnic
/** Interpret <code>array</code> as an array of bits; set the bit at
* <code>tick</code>.
*/
- inert inline void
+ inert inline void
u1set(void *array, uint32_t tick);
/** Interpret <code>array</code> as an array of bits; clear the bit at
* <code>tick</code>.
*/
- inert inline void
+ inert inline void
u1clear(void *array, uint32_t tick);
/** Interpret <code>array</code> as an array of bits; flip the bit at
@@ -160,7 +160,7 @@ inert class Lucy::Util::NumberUtils cnic
/** Interpret <code>array</code> as an array of two-bit integers; set the
* element at <code>tick</code> to <code>value</code>.
*/
- inert inline void
+ inert inline void
u2set(void *array, uint32_t tick, uint8_t value);
/** Interpret <code>array</code> as an array of four-bit integers; return
@@ -172,15 +172,14 @@ inert class Lucy::Util::NumberUtils cnic
/** Interpret <code>array</code> as an array of four-bit integers; set the
* element at <code>tick</code> to <code>value</code>.
*/
- inert inline void
+ inert inline void
u4set(void *array, uint32_t tick, uint8_t value);
}
__C__
static CHY_INLINE void
-lucy_NumUtil_encode_bigend_u16(uint16_t value, void *dest_ptr)
-{
+lucy_NumUtil_encode_bigend_u16(uint16_t value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
#ifdef CHY_BIG_END
memcpy(dest, &value, sizeof(uint16_t));
@@ -192,8 +191,7 @@ lucy_NumUtil_encode_bigend_u16(uint16_t
}
static CHY_INLINE void
-lucy_NumUtil_encode_bigend_u32(uint32_t value, void *dest_ptr)
-{
+lucy_NumUtil_encode_bigend_u32(uint32_t value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
#ifdef CHY_BIG_END
memcpy(dest, &value, sizeof(uint32_t));
@@ -207,8 +205,7 @@ lucy_NumUtil_encode_bigend_u32(uint32_t
}
static CHY_INLINE void
-lucy_NumUtil_encode_bigend_u64(uint64_t value, void *dest_ptr)
-{
+lucy_NumUtil_encode_bigend_u64(uint64_t value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
#ifdef CHY_BIG_END
memcpy(dest, &value, sizeof(uint64_t));
@@ -226,16 +223,14 @@ lucy_NumUtil_encode_bigend_u64(uint64_t
}
static CHY_INLINE uint16_t
-lucy_NumUtil_decode_bigend_u16(void *source)
-{
+lucy_NumUtil_decode_bigend_u16(void *source) {
uint8_t *const buf = (uint8_t*)source;
return (buf[0] << 8) |
(buf[1]);
}
static CHY_INLINE uint32_t
-lucy_NumUtil_decode_bigend_u32(void *source)
-{
+lucy_NumUtil_decode_bigend_u32(void *source) {
uint8_t *const buf = (uint8_t*)source;
return (buf[0] << 24) |
(buf[1] << 16) |
@@ -244,8 +239,7 @@ lucy_NumUtil_decode_bigend_u32(void *sou
}
static CHY_INLINE uint64_t
-lucy_NumUtil_decode_bigend_u64(void *source)
-{
+lucy_NumUtil_decode_bigend_u64(void *source) {
uint8_t *const buf = (uint8_t*)source;
uint64_t high_bits = (buf[0] << 24) |
(buf[1] << 16) |
@@ -260,49 +254,45 @@ lucy_NumUtil_decode_bigend_u64(void *sou
return retval;
}
-static CHY_INLINE void
-lucy_NumUtil_encode_bigend_f32(float value, void *dest_ptr)
-{
+static CHY_INLINE void
+lucy_NumUtil_encode_bigend_f32(float value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
#ifdef CHY_BIG_END
memcpy(dest, &value, sizeof(float));
-#else
- union { float f; uint32_t u32; } duo;
+#else
+ union { float f; uint32_t u32; } duo;
duo.f = value;
lucy_NumUtil_encode_bigend_u32(duo.u32, &dest);
#endif
}
-static CHY_INLINE void
-lucy_NumUtil_encode_bigend_f64(double value, void *dest_ptr)
-{
+static CHY_INLINE void
+lucy_NumUtil_encode_bigend_f64(double value, void *dest_ptr) {
uint8_t *dest = *(uint8_t**)dest_ptr;
#ifdef CHY_BIG_END
memcpy(dest, &value, sizeof(double));
-#else
- union { double d; uint64_t u64; } duo;
+#else
+ union { double d; uint64_t u64; } duo;
duo.d = value;
lucy_NumUtil_encode_bigend_u64(duo.u64, &dest);
#endif
}
-static CHY_INLINE float
-lucy_NumUtil_decode_bigend_f32(void *source)
-{
+static CHY_INLINE float
+lucy_NumUtil_decode_bigend_f32(void *source) {
union { float f; uint32_t u32; } duo;
memcpy(&duo, source, sizeof(float));
-#ifdef CHY_LITTLE_END
+#ifdef CHY_LITTLE_END
duo.u32 = lucy_NumUtil_decode_bigend_u32(&duo.u32);
#endif
return duo.f;
}
-static CHY_INLINE double
-lucy_NumUtil_decode_bigend_f64(void *source)
-{
+static CHY_INLINE double
+lucy_NumUtil_decode_bigend_f64(void *source) {
union { double d; uint64_t u64; } duo;
memcpy(&duo, source, sizeof(double));
-#ifdef CHY_LITTLE_END
+#ifdef CHY_LITTLE_END
duo.u64 = lucy_NumUtil_decode_bigend_u64(&duo.u64);
#endif
return duo.d;
@@ -312,8 +302,7 @@ lucy_NumUtil_decode_bigend_f64(void *sou
#define LUCY_NUMUTIL_C64_MAX_BYTES ((sizeof(uint64_t) * 8 / 7) + 1) // 10
static CHY_INLINE void
-lucy_NumUtil_encode_c32(uint32_t value, char **out_buf)
-{
+lucy_NumUtil_encode_c32(uint32_t value, char **out_buf) {
uint8_t buf[LUCY_NUMUTIL_C32_MAX_BYTES];
uint8_t *const limit = buf + sizeof(buf);
uint8_t *ptr = limit - 1;
@@ -332,8 +321,7 @@ lucy_NumUtil_encode_c32(uint32_t value,
}
static CHY_INLINE void
-lucy_NumUtil_encode_c64(uint64_t value, char **out_buf)
-{
+lucy_NumUtil_encode_c64(uint64_t value, char **out_buf) {
uint8_t buf[LUCY_NUMUTIL_C64_MAX_BYTES];
uint8_t *const limit = buf + sizeof(buf);
uint8_t *ptr = limit - 1;
@@ -352,8 +340,7 @@ lucy_NumUtil_encode_c64(uint64_t value,
}
static CHY_INLINE void
-lucy_NumUtil_encode_padded_c32(uint32_t value, char **out_buf)
-{
+lucy_NumUtil_encode_padded_c32(uint32_t value, char **out_buf) {
uint8_t buf[LUCY_NUMUTIL_C32_MAX_BYTES]
= { 0x80, 0x80, 0x80, 0x80, 0x80 };
uint8_t *const limit = buf + sizeof(buf);
@@ -380,8 +367,7 @@ lucy_NumUtil_encode_padded_c32(uint32_t
} while (0)
static CHY_INLINE uint32_t
-lucy_NumUtil_decode_c32(char **source_ptr)
-{
+lucy_NumUtil_decode_c32(char **source_ptr) {
char *source = *source_ptr;
uint32_t decoded;
LUCY_NUMUTIL_DECODE_CINT(decoded, source);
@@ -390,8 +376,7 @@ lucy_NumUtil_decode_c32(char **source_pt
}
static CHY_INLINE uint64_t
-lucy_NumUtil_decode_c64(char **source_ptr)
-{
+lucy_NumUtil_decode_c64(char **source_ptr) {
char *source = *source_ptr;
uint64_t decoded;
LUCY_NUMUTIL_DECODE_CINT(decoded, source);
@@ -400,34 +385,30 @@ lucy_NumUtil_decode_c64(char **source_pt
}
static CHY_INLINE void
-lucy_NumUtil_skip_cint(char **source_ptr)
-{
+lucy_NumUtil_skip_cint(char **source_ptr) {
uint8_t *ptr = *(uint8_t**)source_ptr;
while ((*ptr++ & 0x80) != 0) { }
*source_ptr = (char*)ptr;
}
static CHY_INLINE chy_bool_t
-lucy_NumUtil_u1get(void *array, uint32_t tick)
-{
+lucy_NumUtil_u1get(void *array, uint32_t tick) {
uint8_t *const u8bits = (uint8_t*)array;
const uint32_t byte_offset = tick >> 3;
const uint8_t mask = lucy_NumUtil_u1masks[tick & 0x7];
return !((u8bits[byte_offset] & mask) == 0);
}
-static CHY_INLINE void
-lucy_NumUtil_u1set(void *array, uint32_t tick)
-{
+static CHY_INLINE void
+lucy_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 = lucy_NumUtil_u1masks[tick & 0x7];
u8bits[byte_offset] |= mask;
}
-static CHY_INLINE void
-lucy_NumUtil_u1clear(void *array, uint32_t tick)
-{
+static CHY_INLINE void
+lucy_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 = lucy_NumUtil_u1masks[tick & 0x7];
@@ -435,8 +416,7 @@ lucy_NumUtil_u1clear(void *array, uint32
}
static CHY_INLINE void
-lucy_NumUtil_u1flip(void *array, uint32_t tick)
-{
+lucy_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 = lucy_NumUtil_u1masks[tick & 0x7];
@@ -444,17 +424,15 @@ lucy_NumUtil_u1flip(void *array, uint32_
}
static CHY_INLINE uint8_t
-lucy_NumUtil_u2get(void *array, uint32_t tick)
-{
+lucy_NumUtil_u2get(void *array, uint32_t tick) {
uint8_t *ints = (uint8_t*)array;
- uint8_t byte = ints[ (tick >> 2) ];
- int shift = lucy_NumUtil_u2shifts[ tick & 0x3 ];
+ uint8_t byte = ints[(tick >> 2)];
+ int shift = lucy_NumUtil_u2shifts[tick & 0x3];
return (byte >> shift) & 0x3;
}
-static CHY_INLINE void
-lucy_NumUtil_u2set(void *array, uint32_t tick, uint8_t value)
-{
+static CHY_INLINE void
+lucy_NumUtil_u2set(void *array, uint32_t tick, uint8_t value) {
uint8_t *ints = (uint8_t*)array;
unsigned sub_tick = tick & 0x3;
int shift = lucy_NumUtil_u2shifts[sub_tick];
@@ -466,17 +444,15 @@ lucy_NumUtil_u2set(void *array, uint32_t
static CHY_INLINE uint8_t
-lucy_NumUtil_u4get(void *array, uint32_t tick)
-{
+lucy_NumUtil_u4get(void *array, uint32_t tick) {
uint8_t *ints = (uint8_t*)array;
- uint8_t byte = ints[ (tick >> 1) ];
- int shift = lucy_NumUtil_u4shifts[(tick & 1)];
+ uint8_t byte = ints[(tick >> 1)];
+ int shift = lucy_NumUtil_u4shifts[(tick & 1)];
return (byte >> shift) & 0xF;
}
-static CHY_INLINE void
-lucy_NumUtil_u4set(void *array, uint32_t tick, uint8_t value)
-{
+static CHY_INLINE void
+lucy_NumUtil_u4set(void *array, uint32_t tick, uint8_t value) {
uint8_t *ints = (uint8_t*)array;
unsigned sub_tick = tick & 0x1;
int shift = lucy_NumUtil_u4shifts[sub_tick];
Modified: incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c Sun May 1 23:50:24 2011
@@ -27,7 +27,7 @@ static void
S_put(PriorityQueue *self, Obj *element);
// Free all the elements in the heap and set size to 0.
-static void
+static void
S_clear(PriorityQueue *self);
// Heap adjuster.
@@ -39,8 +39,7 @@ static void
S_down_heap(PriorityQueue *self);
PriorityQueue*
-PriQ_init(PriorityQueue *self, uint32_t max_size)
-{
+PriQ_init(PriorityQueue *self, uint32_t max_size) {
if (max_size == U32_MAX) {
THROW(ERR, "max_size too large: %u32", max_size);
}
@@ -50,7 +49,7 @@ PriQ_init(PriorityQueue *self, uint32_t
self->size = 0;
// Assign.
- self->max_size = max_size;
+ self->max_size = max_size;
// Allocate space for the heap, assign all slots to NULL.
self->heap = (Obj**)CALLOCATE(heap_size, sizeof(Obj*));
@@ -60,8 +59,7 @@ PriQ_init(PriorityQueue *self, uint32_t
}
void
-PriQ_destroy(PriorityQueue *self)
-{
+PriQ_destroy(PriorityQueue *self) {
if (self->heap) {
S_clear(self);
FREEMEM(self->heap);
@@ -70,28 +68,28 @@ PriQ_destroy(PriorityQueue *self)
}
uint32_t
-PriQ_get_size(PriorityQueue *self) { return self->size; }
+PriQ_get_size(PriorityQueue *self) {
+ return self->size;
+}
static void
-S_put(PriorityQueue *self, Obj *element)
-{
+S_put(PriorityQueue *self, Obj *element) {
// Increment size.
if (self->size >= self->max_size) {
- THROW(ERR, "PriorityQueue exceeded max_size: %u32 %u32", self->size,
- self->max_size);
+ THROW(ERR, "PriorityQueue exceeded max_size: %u32 %u32", self->size,
+ self->max_size);
}
self->size++;
// Put element into heap.
- self->heap[ self->size ] = element;
+ self->heap[self->size] = element;
// Adjust heap.
S_up_heap(self);
}
bool_t
-PriQ_insert(PriorityQueue *self, Obj *element)
-{
+PriQ_insert(PriorityQueue *self, Obj *element) {
Obj *least = PriQ_Jostle(self, element);
DECREF(least);
if (element == least) return false;
@@ -99,8 +97,7 @@ PriQ_insert(PriorityQueue *self, Obj *el
}
Obj*
-PriQ_jostle(PriorityQueue *self, Obj *element)
-{
+PriQ_jostle(PriorityQueue *self, Obj *element) {
// Absorb element if there's a vacancy.
if (self->size < self->max_size) {
S_put(self, element);
@@ -112,7 +109,7 @@ PriQ_jostle(PriorityQueue *self, Obj *el
}
else {
Obj *scratch = PriQ_Peek(self);
- if ( !PriQ_Less_Than(self, element, scratch) ) {
+ if (!PriQ_Less_Than(self, element, scratch)) {
// If the new element belongs in the queue, replace something.
Obj *retval = self->heap[1];
self->heap[1] = element;
@@ -126,15 +123,14 @@ PriQ_jostle(PriorityQueue *self, Obj *el
}
Obj*
-PriQ_pop(PriorityQueue *self)
-{
+PriQ_pop(PriorityQueue *self) {
if (self->size > 0) {
// Save the first value.
Obj *result = self->heap[1];
// Move last to first and adjust heap.
- self->heap[1] = self->heap[ self->size ];
- self->heap[ self->size ] = NULL;
+ self->heap[1] = self->heap[self->size];
+ self->heap[self->size] = NULL;
self->size--;
S_down_heap(self);
@@ -147,14 +143,13 @@ PriQ_pop(PriorityQueue *self)
}
VArray*
-PriQ_pop_all(PriorityQueue *self)
-{
+PriQ_pop_all(PriorityQueue *self) {
VArray *retval = VA_new(self->size);
// Map the queue nodes onto the array in reverse order.
if (self->size) {
uint32_t i;
- for (i = self->size; i--; ) {
+ for (i = self->size; i--;) {
Obj *const elem = PriQ_Pop(self);
VA_Store(retval, i, elem);
}
@@ -164,8 +159,7 @@ PriQ_pop_all(PriorityQueue *self)
}
Obj*
-PriQ_peek(PriorityQueue *self)
-{
+PriQ_peek(PriorityQueue *self) {
if (self->size > 0) {
return self->heap[1];
}
@@ -174,9 +168,8 @@ PriQ_peek(PriorityQueue *self)
}
}
-static void
-S_clear(PriorityQueue *self)
-{
+static void
+S_clear(PriorityQueue *self) {
uint32_t i;
Obj **elem_ptr = (self->heap + 1);
@@ -185,20 +178,19 @@ S_clear(PriorityQueue *self)
DECREF(*elem_ptr);
*elem_ptr = NULL;
elem_ptr++;
- }
+ }
self->size = 0;
}
static void
-S_up_heap(PriorityQueue *self)
-{
+S_up_heap(PriorityQueue *self) {
uint32_t i = self->size;
uint32_t j = i >> 1;
Obj *const node = self->heap[i]; // save bottom node
- while ( j > 0
- && PriQ_Less_Than(self, node, self->heap[j])
- ) {
+ while (j > 0
+ && PriQ_Less_Than(self, node, self->heap[j])
+ ) {
self->heap[i] = self->heap[j];
i = j;
j = j >> 1;
@@ -207,30 +199,29 @@ S_up_heap(PriorityQueue *self)
}
static void
-S_down_heap(PriorityQueue *self)
-{
+S_down_heap(PriorityQueue *self) {
uint32_t i = 1;
uint32_t j = i << 1;
uint32_t k = j + 1;
Obj *node = self->heap[i]; // save top node
// Find smaller child.
- if ( k <= self->size
+ if (k <= self->size
&& PriQ_Less_Than(self, self->heap[k], self->heap[j])
- ) {
+ ) {
j = k;
}
- while ( j <= self->size
+ while (j <= self->size
&& PriQ_Less_Than(self, self->heap[j], node)
- ) {
+ ) {
self->heap[i] = self->heap[j];
i = j;
j = i << 1;
k = j + 1;
- if ( k <= self->size
+ if (k <= self->size
&& PriQ_Less_Than(self, self->heap[k], self->heap[j])
- ) {
+ ) {
j = k;
}
}
Modified: incubator/lucy/trunk/core/Lucy/Util/ProcessID.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/ProcessID.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/ProcessID.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/ProcessID.c Sun May 1 23:50:24 2011
@@ -22,15 +22,13 @@
#include <Windows.h>
#include <process.h>
-int
-lucy_PID_getpid(void)
-{
+int
+lucy_PID_getpid(void) {
return GetCurrentProcessId();
}
chy_bool_t
-lucy_PID_active(int pid)
-{
+lucy_PID_active(int pid) {
// Attempt to open a handle to the process with permissions to terminate
// -- but don't actually terminate.
HANDLE handle = OpenProcess(PROCESS_TERMINATE, false, pid);
@@ -57,15 +55,13 @@ lucy_PID_active(int pid)
#include <signal.h>
#include <errno.h>
-int
-lucy_PID_getpid(void)
-{
+int
+lucy_PID_getpid(void) {
return getpid();
}
chy_bool_t
-lucy_PID_active(int pid)
-{
+lucy_PID_active(int pid) {
if (kill(pid, 0) == 0) {
return true; // signal succeeded, therefore pid active
}
Modified: incubator/lucy/trunk/core/Lucy/Util/ProcessID.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/ProcessID.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/ProcessID.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Util/ProcessID.cfh Sun May 1 23:50:24 2011
@@ -19,10 +19,10 @@ parcel Lucy;
/** Provide platform-compatible process ID functions.
*/
inert class Lucy::Util::ProcessID cnick PID {
-
+
/** Return the ID for the current process.
*/
- inert int
+ inert int
getpid(void);
/** Return true if the supplied process ID is associated with an active