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 [9/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/ clo...
Modified: incubator/lucy/trunk/core/Lucy/Index/Snapshot.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/Snapshot.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/Snapshot.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/Snapshot.c Sun May 1 23:50:24 2011
@@ -31,15 +31,13 @@ int32_t Snapshot_current_file_format = 2
static int32_t Snapshot_current_file_subformat = 1;
Snapshot*
-Snapshot_new()
-{
+Snapshot_new() {
Snapshot *self = (Snapshot*)VTable_Make_Obj(SNAPSHOT);
return Snapshot_init(self);
}
static void
-S_zero_out(Snapshot *self)
-{
+S_zero_out(Snapshot *self) {
DECREF(self->entries);
DECREF(self->path);
self->entries = Hash_new(0);
@@ -47,31 +45,27 @@ S_zero_out(Snapshot *self)
}
Snapshot*
-Snapshot_init(Snapshot *self)
-{
+Snapshot_init(Snapshot *self) {
S_zero_out(self);
return self;
}
void
-Snapshot_destroy(Snapshot *self)
-{
+Snapshot_destroy(Snapshot *self) {
DECREF(self->entries);
DECREF(self->path);
SUPER_DESTROY(self, SNAPSHOT);
}
void
-Snapshot_add_entry(Snapshot *self, const CharBuf *entry)
-{
+Snapshot_add_entry(Snapshot *self, const CharBuf *entry) {
Hash_Store(self->entries, (Obj*)entry, INCREF(&EMPTY));
}
bool_t
-Snapshot_delete_entry(Snapshot *self, const CharBuf *entry)
-{
+Snapshot_delete_entry(Snapshot *self, const CharBuf *entry) {
Obj *val = Hash_Delete(self->entries, (Obj*)entry);
- if (val) {
+ if (val) {
Obj_Dec_RefCount(val);
return true;
}
@@ -81,50 +75,53 @@ Snapshot_delete_entry(Snapshot *self, co
}
VArray*
-Snapshot_list(Snapshot *self) {
- return Hash_Keys(self->entries);
+Snapshot_list(Snapshot *self) {
+ return Hash_Keys(self->entries);
}
uint32_t
-Snapshot_num_entries(Snapshot *self) { return Hash_Get_Size(self->entries); }
+Snapshot_num_entries(Snapshot *self) {
+ return Hash_Get_Size(self->entries);
+}
void
-Snapshot_set_path(Snapshot *self, const CharBuf *path)
-{
+Snapshot_set_path(Snapshot *self, const CharBuf *path) {
DECREF(self->path);
self->path = path ? CB_Clone(path) : NULL;
}
CharBuf*
-Snapshot_get_path(Snapshot *self) { return self->path; }
+Snapshot_get_path(Snapshot *self) {
+ return self->path;
+}
Snapshot*
-Snapshot_read_file(Snapshot *self, Folder *folder, const CharBuf *path)
-{
+Snapshot_read_file(Snapshot *self, Folder *folder, const CharBuf *path) {
// Eliminate all prior data. Pick a snapshot file.
S_zero_out(self);
self->path = path ? CB_Clone(path) : IxFileNames_latest_snapshot(folder);
if (self->path) {
- Hash *snap_data = (Hash*)CERTIFY(
- Json_slurp_json(folder, self->path), HASH);
- Obj *format_obj = CERTIFY(
- Hash_Fetch_Str(snap_data, "format", 6), OBJ);
+ Hash *snap_data
+ = (Hash*)CERTIFY(Json_slurp_json(folder, self->path), HASH);
+ Obj *format_obj
+ = CERTIFY(Hash_Fetch_Str(snap_data, "format", 6), OBJ);
int32_t format = (int32_t)Obj_To_I64(format_obj);
Obj *subformat_obj = Hash_Fetch_Str(snap_data, "subformat", 9);
- int32_t subformat = subformat_obj
- ? (int32_t)Obj_To_I64(subformat_obj)
- : 0;
+ int32_t subformat = subformat_obj
+ ? (int32_t)Obj_To_I64(subformat_obj)
+ : 0;
// Verify that we can read the index properly.
if (format > Snapshot_current_file_format) {
THROW(ERR, "Snapshot format too recent: %i32, %i32",
- format, Snapshot_current_file_format);
+ format, Snapshot_current_file_format);
}
// Build up list of entries.
VArray *list = (VArray*)CERTIFY(
- Hash_Fetch_Str(snap_data, "entries", 7), VARRAY);
+ Hash_Fetch_Str(snap_data, "entries", 7),
+ VARRAY);
INCREF(list);
if (format == 1 || (format == 2 && subformat < 1)) {
VArray *cleaned = S_clean_segment_contents(list);
@@ -133,8 +130,8 @@ Snapshot_read_file(Snapshot *self, Folde
}
Hash_Clear(self->entries);
for (uint32_t i = 0, max = VA_Get_Size(list); i < max; i++) {
- CharBuf *entry = (CharBuf*)CERTIFY(
- VA_Fetch(list, i), CHARBUF);
+ CharBuf *entry
+ = (CharBuf*)CERTIFY(VA_Fetch(list, i), CHARBUF);
Hash_Store(self->entries, (Obj*)entry, INCREF(&EMPTY));
}
@@ -146,8 +143,7 @@ Snapshot_read_file(Snapshot *self, Folde
}
static VArray*
-S_clean_segment_contents(VArray *orig)
-{
+S_clean_segment_contents(VArray *orig) {
// Since Snapshot format 2, no DataReader has depended on individual files
// within segment directories being listed. Filter these files because
// they cause a problem with FilePurger.
@@ -166,8 +162,7 @@ S_clean_segment_contents(VArray *orig)
void
-Snapshot_write_file(Snapshot *self, Folder *folder, const CharBuf *path)
-{
+Snapshot_write_file(Snapshot *self, Folder *folder, const CharBuf *path) {
Hash *all_data = Hash_new(0);
VArray *list = Snapshot_List(self);
@@ -195,10 +190,10 @@ Snapshot_write_file(Snapshot *self, Fold
Hash_Store_Str(all_data, "entries", 7, (Obj*)list);
// Create a JSON-izable data structure.
- Hash_Store_Str(all_data, "format", 6,
- (Obj*)CB_newf("%i32", (int32_t)Snapshot_current_file_format) );
- Hash_Store_Str(all_data, "subformat", 9,
- (Obj*)CB_newf("%i32", (int32_t)Snapshot_current_file_subformat) );
+ Hash_Store_Str(all_data, "format", 6,
+ (Obj*)CB_newf("%i32", (int32_t)Snapshot_current_file_format));
+ Hash_Store_Str(all_data, "subformat", 9,
+ (Obj*)CB_newf("%i32", (int32_t)Snapshot_current_file_subformat));
// Write out JSON-ized data to the new file.
Json_spew_json((Obj*)all_data, folder, self->path);
Modified: incubator/lucy/trunk/core/Lucy/Index/Snapshot.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/Snapshot.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/Snapshot.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Index/Snapshot.cfh Sun May 1 23:50:24 2011
@@ -33,13 +33,13 @@ class Lucy::Index::Snapshot inherits Luc
inert int32_t current_file_format;
- public inert incremented Snapshot*
+ public inert incremented Snapshot*
new();
-
+
/**
* Constructor. Takes no arguments.
*/
- public inert Snapshot*
+ public inert Snapshot*
init(Snapshot *self);
/** Return an array of all entries.
@@ -100,7 +100,7 @@ class Lucy::Index::Snapshot inherits Luc
public nullable CharBuf*
Get_Path(Snapshot *self);
- public void
+ public void
Destroy(Snapshot *self);
}
Modified: incubator/lucy/trunk/core/Lucy/Index/SortCache.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortCache.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortCache.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortCache.c Sun May 1 23:50:24 2011
@@ -23,14 +23,13 @@
SortCache*
SortCache_init(SortCache *self, const CharBuf *field, FieldType *type,
void *ords, int32_t cardinality, int32_t doc_max, int32_t null_ord,
- int32_t ord_width)
-{
+ int32_t ord_width) {
// Init.
self->native_ords = false;
// Assign.
- if (!FType_Sortable(type)) {
- THROW(ERR, "Non-sortable FieldType for %o", field);
+ if (!FType_Sortable(type)) {
+ THROW(ERR, "Non-sortable FieldType for %o", field);
}
self->field = CB_Clone(field);
self->type = (FieldType*)INCREF(type);
@@ -45,23 +44,25 @@ SortCache_init(SortCache *self, const Ch
}
void
-SortCache_destroy(SortCache *self)
-{
+SortCache_destroy(SortCache *self) {
DECREF(self->field);
DECREF(self->type);
SUPER_DESTROY(self, SORTCACHE);
}
bool_t
-SortCache_get_native_ords(SortCache *self) { return self->native_ords; }
+SortCache_get_native_ords(SortCache *self) {
+ return self->native_ords;
+}
+
void
-SortCache_set_native_ords(SortCache *self, bool_t native_ords)
- { self->native_ords = native_ords; }
+SortCache_set_native_ords(SortCache *self, bool_t native_ords) {
+ self->native_ords = native_ords;
+}
int32_t
-SortCache_ordinal(SortCache *self, int32_t doc_id)
-{
- if ((uint32_t)doc_id > (uint32_t)self->doc_max) {
+SortCache_ordinal(SortCache *self, int32_t doc_id) {
+ if ((uint32_t)doc_id > (uint32_t)self->doc_max) {
THROW(ERR, "Out of range: %i32 > %i32", doc_id, self->doc_max);
}
switch (self->ord_width) {
@@ -69,10 +70,10 @@ SortCache_ordinal(SortCache *self, int32
case 2: return NumUtil_u2get(self->ords, doc_id);
case 4: return NumUtil_u4get(self->ords, doc_id);
case 8: {
- uint8_t *ints = (uint8_t*)self->ords;
- return ints[doc_id];
- }
- case 16:
+ uint8_t *ints = (uint8_t*)self->ords;
+ return ints[doc_id];
+ }
+ case 16:
if (self->native_ords) {
uint16_t *ints = (uint16_t*)self->ords;
return ints[doc_id];
@@ -93,28 +94,27 @@ SortCache_ordinal(SortCache *self, int32
return NumUtil_decode_bigend_u32(bytes);
}
default: {
- THROW(ERR, "Invalid ord width: %i32", self->ord_width);
- UNREACHABLE_RETURN(int32_t);
- }
+ THROW(ERR, "Invalid ord width: %i32", self->ord_width);
+ UNREACHABLE_RETURN(int32_t);
+ }
}
}
int32_t
-SortCache_find(SortCache *self, Obj *term)
-{
- FieldType *const type = self->type;
- int32_t lo = 0;
- int32_t hi = self->cardinality - 1;
- int32_t result = -100;
- Obj *blank = SortCache_Make_Blank(self);
+SortCache_find(SortCache *self, Obj *term) {
+ FieldType *const type = self->type;
+ int32_t lo = 0;
+ int32_t hi = self->cardinality - 1;
+ int32_t result = -100;
+ Obj *blank = SortCache_Make_Blank(self);
- if ( term != NULL
+ if (term != NULL
&& !Obj_Is_A(term, Obj_Get_VTable(blank))
&& !Obj_Is_A(blank, Obj_Get_VTable(term))
- ) {
+ ) {
THROW(ERR, "SortCache error for field %o: term is a %o, and not "
- "comparable to a %o", self->field, Obj_Get_Class_Name(term),
- Obj_Get_Class_Name(blank));
+ "comparable to a %o", self->field, Obj_Get_Class_Name(term),
+ Obj_Get_Class_Name(blank));
}
// Binary search.
@@ -136,7 +136,7 @@ SortCache_find(SortCache *self, Obj *ter
DECREF(blank);
- if (hi < 0) {
+ if (hi < 0) {
// Target is "less than" the first cache entry.
return -1;
}
@@ -150,12 +150,23 @@ SortCache_find(SortCache *self, Obj *ter
}
void*
-SortCache_get_ords(SortCache *self) { return self->ords; }
+SortCache_get_ords(SortCache *self) {
+ return self->ords;
+}
+
int32_t
-SortCache_get_cardinality(SortCache *self) { return self->cardinality; }
+SortCache_get_cardinality(SortCache *self) {
+ return self->cardinality;
+}
+
int32_t
-SortCache_get_null_ord(SortCache *self) { return self->null_ord; }
+SortCache_get_null_ord(SortCache *self) {
+ return self->null_ord;
+}
+
int32_t
-SortCache_get_ord_width(SortCache *self) { return self->ord_width; }
+SortCache_get_ord_width(SortCache *self) {
+ return self->ord_width;
+}
Modified: incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.c Sun May 1 23:50:24 2011
@@ -31,10 +31,9 @@
NumericSortCache*
NumSortCache_init(NumericSortCache *self, const CharBuf *field,
- FieldType *type, int32_t cardinality, int32_t doc_max,
- int32_t null_ord, int32_t ord_width, InStream *ord_in,
- InStream *dat_in)
-{
+ FieldType *type, int32_t cardinality, int32_t doc_max,
+ int32_t null_ord, int32_t ord_width, InStream *ord_in,
+ InStream *dat_in) {
// Validate.
if (!type || !FType_Sortable(type) || !FType_Is_A(type, NUMERICTYPE)) {
DECREF(self);
@@ -45,12 +44,12 @@ NumSortCache_init(NumericSortCache *self
int64_t ord_len = InStream_Length(ord_in);
void *ords = InStream_Buf(ord_in, (size_t)ord_len);
SortCache_init((SortCache*)self, field, type, ords, cardinality, doc_max,
- null_ord, ord_width);
+ null_ord, ord_width);
// Assign.
self->ord_in = (InStream*)INCREF(ord_in);
self->dat_in = (InStream*)INCREF(dat_in);
-
+
// Validate ord file length.
double BITS_PER_BYTE = 8.0;
double docs_per_byte = BITS_PER_BYTE / self->ord_width;
@@ -58,7 +57,7 @@ NumSortCache_init(NumericSortCache *self
if (max_ords < self->doc_max + 1) {
DECREF(self);
THROW(ERR, "Conflict between ord count max %f64 and doc_max %i32 for "
- "field %o", max_ords, self->doc_max, field);
+ "field %o", max_ords, self->doc_max, field);
}
ABSTRACT_CLASS_CHECK(self, NUMERICSORTCACHE);
@@ -66,14 +65,13 @@ NumSortCache_init(NumericSortCache *self
}
void
-NumSortCache_destroy(NumericSortCache *self)
-{
- if (self->ord_in) {
- InStream_Close(self->ord_in);
+NumSortCache_destroy(NumericSortCache *self) {
+ if (self->ord_in) {
+ InStream_Close(self->ord_in);
InStream_Dec_RefCount(self->ord_in);
}
- if (self->dat_in) {
- InStream_Close(self->dat_in);
+ if (self->dat_in) {
+ InStream_Close(self->dat_in);
InStream_Dec_RefCount(self->dat_in);
}
SUPER_DESTROY(self, NUMERICSORTCACHE);
@@ -82,32 +80,29 @@ NumSortCache_destroy(NumericSortCache *s
/***************************************************************************/
Float64SortCache*
-F64SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord, int32_t ord_width,
- InStream *ord_in, InStream *dat_in)
-{
- Float64SortCache *self
+F64SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
+ int32_t doc_max, int32_t null_ord, int32_t ord_width,
+ InStream *ord_in, InStream *dat_in) {
+ Float64SortCache *self
= (Float64SortCache*)VTable_Make_Obj(FLOAT64SORTCACHE);
- return F64SortCache_init(self, field, type, cardinality, doc_max,
- null_ord, ord_width, ord_in, dat_in);
+ return F64SortCache_init(self, field, type, cardinality, doc_max,
+ null_ord, ord_width, ord_in, dat_in);
}
Float64SortCache*
F64SortCache_init(Float64SortCache *self, const CharBuf *field,
- FieldType *type, int32_t cardinality, int32_t doc_max,
- int32_t null_ord, int32_t ord_width, InStream *ord_in,
- InStream *dat_in)
-{
+ FieldType *type, int32_t cardinality, int32_t doc_max,
+ int32_t null_ord, int32_t ord_width, InStream *ord_in,
+ InStream *dat_in) {
NumSortCache_init((NumericSortCache*)self, field, type, cardinality,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ doc_max, null_ord, ord_width, ord_in, dat_in);
return self;
}
Obj*
-F64SortCache_value(Float64SortCache *self, int32_t ord, Obj *blank)
-{
- if (ord == self->null_ord ) {
- return NULL;
+F64SortCache_value(Float64SortCache *self, int32_t ord, Obj *blank) {
+ if (ord == self->null_ord) {
+ return NULL;
}
else if (ord < 0) {
THROW(ERR, "Ordinal less than 0 for %o: %i32", self->field, ord);
@@ -121,8 +116,7 @@ F64SortCache_value(Float64SortCache *sel
}
Float64*
-F64SortCache_make_blank(Float64SortCache *self)
-{
+F64SortCache_make_blank(Float64SortCache *self) {
UNUSED_VAR(self);
return Float64_new(0.0);
}
@@ -130,32 +124,29 @@ F64SortCache_make_blank(Float64SortCache
/***************************************************************************/
Float32SortCache*
-F32SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord, int32_t ord_width,
- InStream *ord_in, InStream *dat_in)
-{
- Float32SortCache *self
+F32SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
+ int32_t doc_max, int32_t null_ord, int32_t ord_width,
+ InStream *ord_in, InStream *dat_in) {
+ Float32SortCache *self
= (Float32SortCache*)VTable_Make_Obj(FLOAT32SORTCACHE);
- return F32SortCache_init(self, field, type, cardinality, doc_max,
- null_ord, ord_width, ord_in, dat_in);
+ return F32SortCache_init(self, field, type, cardinality, doc_max,
+ null_ord, ord_width, ord_in, dat_in);
}
Float32SortCache*
F32SortCache_init(Float32SortCache *self, const CharBuf *field,
- FieldType *type, int32_t cardinality, int32_t doc_max,
- int32_t null_ord, int32_t ord_width, InStream *ord_in,
- InStream *dat_in)
-{
+ FieldType *type, int32_t cardinality, int32_t doc_max,
+ int32_t null_ord, int32_t ord_width, InStream *ord_in,
+ InStream *dat_in) {
NumSortCache_init((NumericSortCache*)self, field, type, cardinality,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ doc_max, null_ord, ord_width, ord_in, dat_in);
return self;
}
Obj*
-F32SortCache_value(Float32SortCache *self, int32_t ord, Obj *blank)
-{
- if (ord == self->null_ord ) {
- return NULL;
+F32SortCache_value(Float32SortCache *self, int32_t ord, Obj *blank) {
+ if (ord == self->null_ord) {
+ return NULL;
}
else if (ord < 0) {
THROW(ERR, "Ordinal less than 0 for %o: %i32", self->field, ord);
@@ -169,8 +160,7 @@ F32SortCache_value(Float32SortCache *sel
}
Float32*
-F32SortCache_make_blank(Float32SortCache *self)
-{
+F32SortCache_make_blank(Float32SortCache *self) {
UNUSED_VAR(self);
return Float32_new(0.0f);
}
@@ -178,32 +168,29 @@ F32SortCache_make_blank(Float32SortCache
/***************************************************************************/
Int32SortCache*
-I32SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
+I32SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
int32_t doc_max, int32_t null_ord, int32_t ord_width,
- InStream *ord_in, InStream *dat_in)
-{
- Int32SortCache *self
+ InStream *ord_in, InStream *dat_in) {
+ Int32SortCache *self
= (Int32SortCache*)VTable_Make_Obj(INT32SORTCACHE);
- return I32SortCache_init(self, field, type, cardinality, doc_max,
- null_ord, ord_width, ord_in, dat_in);
+ return I32SortCache_init(self, field, type, cardinality, doc_max,
+ null_ord, ord_width, ord_in, dat_in);
}
Int32SortCache*
I32SortCache_init(Int32SortCache *self, const CharBuf *field,
- FieldType *type, int32_t cardinality, int32_t doc_max,
- int32_t null_ord, int32_t ord_width, InStream *ord_in,
- InStream *dat_in)
-{
+ FieldType *type, int32_t cardinality, int32_t doc_max,
+ int32_t null_ord, int32_t ord_width, InStream *ord_in,
+ InStream *dat_in) {
NumSortCache_init((NumericSortCache*)self, field, type, cardinality,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ doc_max, null_ord, ord_width, ord_in, dat_in);
return self;
}
Obj*
-I32SortCache_value(Int32SortCache *self, int32_t ord, Obj *blank)
-{
- if (ord == self->null_ord ) {
- return NULL;
+I32SortCache_value(Int32SortCache *self, int32_t ord, Obj *blank) {
+ if (ord == self->null_ord) {
+ return NULL;
}
else if (ord < 0) {
THROW(ERR, "Ordinal less than 0 for %o: %i32", self->field, ord);
@@ -217,8 +204,7 @@ I32SortCache_value(Int32SortCache *self,
}
Integer32*
-I32SortCache_make_blank(Int32SortCache *self)
-{
+I32SortCache_make_blank(Int32SortCache *self) {
UNUSED_VAR(self);
return Int32_new(0);
}
@@ -226,32 +212,29 @@ I32SortCache_make_blank(Int32SortCache *
/***************************************************************************/
Int64SortCache*
-I64SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord, int32_t ord_width,
- InStream *ord_in, InStream *dat_in)
-{
- Int64SortCache *self
+I64SortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
+ int32_t doc_max, int32_t null_ord, int32_t ord_width,
+ InStream *ord_in, InStream *dat_in) {
+ Int64SortCache *self
= (Int64SortCache*)VTable_Make_Obj(INT64SORTCACHE);
- return I64SortCache_init(self, field, type, cardinality, doc_max,
- null_ord, ord_width, ord_in, dat_in);
+ return I64SortCache_init(self, field, type, cardinality, doc_max,
+ null_ord, ord_width, ord_in, dat_in);
}
Int64SortCache*
I64SortCache_init(Int64SortCache *self, const CharBuf *field,
- FieldType *type, int32_t cardinality, int32_t doc_max,
- int32_t null_ord, int32_t ord_width, InStream *ord_in,
- InStream *dat_in)
-{
+ FieldType *type, int32_t cardinality, int32_t doc_max,
+ int32_t null_ord, int32_t ord_width, InStream *ord_in,
+ InStream *dat_in) {
NumSortCache_init((NumericSortCache*)self, field, type, cardinality,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ doc_max, null_ord, ord_width, ord_in, dat_in);
return self;
}
Obj*
-I64SortCache_value(Int64SortCache *self, int32_t ord, Obj *blank)
-{
- if (ord == self->null_ord ) {
- return NULL;
+I64SortCache_value(Int64SortCache *self, int32_t ord, Obj *blank) {
+ if (ord == self->null_ord) {
+ return NULL;
}
else if (ord < 0) {
THROW(ERR, "Ordinal less than 0 for %o: %i32", self->field, ord);
@@ -265,8 +248,7 @@ I64SortCache_value(Int64SortCache *self,
}
Integer64*
-I64SortCache_make_blank(Int64SortCache *self)
-{
+I64SortCache_make_blank(Int64SortCache *self) {
UNUSED_VAR(self);
return Int64_new(0);
}
Modified: incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortCache/NumericSortCache.cfh Sun May 1 23:50:24 2011
@@ -23,7 +23,7 @@ class Lucy::Index::SortCache::NumericSor
InStream *dat_in;
inert NumericSortCache*
- init(NumericSortCache *self, const CharBuf *field, FieldType *type,
+ init(NumericSortCache *self, const CharBuf *field, FieldType *type,
int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
int32_t ord_width, InStream *ord_in, InStream *dat_in);
@@ -36,7 +36,7 @@ class Lucy::Index::SortCache::Float64Sor
public inert incremented Float64SortCache*
new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
+ int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
InStream *ord_in, InStream *dat_in);
public inert Float64SortCache*
@@ -56,7 +56,7 @@ class Lucy::Index::SortCache::Float32Sor
public inert incremented Float32SortCache*
new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
+ int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
InStream *ord_in, InStream *dat_in);
public inert Float32SortCache*
@@ -76,7 +76,7 @@ class Lucy::Index::SortCache::Int32SortC
public inert incremented Int32SortCache*
new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
+ int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
InStream *ord_in, InStream *dat_in);
public inert Int32SortCache*
@@ -96,7 +96,7 @@ class Lucy::Index::SortCache::Int64SortC
public inert incremented Int64SortCache*
new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
+ int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
InStream *ord_in, InStream *dat_in);
public inert Int64SortCache*
Modified: incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.c Sun May 1 23:50:24 2011
@@ -25,21 +25,19 @@
#include "Lucy/Store/Folder.h"
TextSortCache*
-TextSortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord, int32_t ord_width,
- InStream *ord_in, InStream *ix_in, InStream *dat_in)
-{
+TextSortCache_new(const CharBuf *field, FieldType *type, int32_t cardinality,
+ int32_t doc_max, int32_t null_ord, int32_t ord_width,
+ InStream *ord_in, InStream *ix_in, InStream *dat_in) {
TextSortCache *self = (TextSortCache*)VTable_Make_Obj(TEXTSORTCACHE);
return TextSortCache_init(self, field, type, cardinality, doc_max,
- null_ord, ord_width, ord_in, ix_in, dat_in);
+ null_ord, ord_width, ord_in, ix_in, dat_in);
}
TextSortCache*
TextSortCache_init(TextSortCache *self, const CharBuf *field,
- FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord, int32_t ord_width,
- InStream *ord_in, InStream *ix_in, InStream *dat_in)
-{
+ FieldType *type, int32_t cardinality,
+ int32_t doc_max, int32_t null_ord, int32_t ord_width,
+ InStream *ord_in, InStream *ix_in, InStream *dat_in) {
// Validate.
if (!type || !FType_Sortable(type)) {
DECREF(self);
@@ -50,7 +48,7 @@ TextSortCache_init(TextSortCache *self,
int64_t ord_len = InStream_Length(ord_in);
void *ords = InStream_Buf(ord_in, (size_t)ord_len);
SortCache_init((SortCache*)self, field, type, ords, cardinality, doc_max,
- null_ord, ord_width);
+ null_ord, ord_width);
// Validate ords file length.
double bytes_per_doc = self->ord_width / 8.0;
@@ -58,7 +56,7 @@ TextSortCache_init(TextSortCache *self,
if (max_ords < self->doc_max + 1) {
WARN("ORD WIDTH: %i32 %i32", ord_width, self->ord_width);
THROW(ERR, "Conflict between ord count max %f64 and doc_max %i32 for "
- "field %o", max_ords, doc_max, field);
+ "field %o", max_ords, doc_max, field);
}
// Assign.
@@ -70,35 +68,33 @@ TextSortCache_init(TextSortCache *self,
}
void
-TextSortCache_destroy(TextSortCache *self)
-{
- if (self->ord_in) {
- InStream_Close(self->ord_in);
+TextSortCache_destroy(TextSortCache *self) {
+ if (self->ord_in) {
+ InStream_Close(self->ord_in);
InStream_Dec_RefCount(self->ord_in);
}
- if (self->ix_in) {
- InStream_Close(self->ix_in);
+ if (self->ix_in) {
+ InStream_Close(self->ix_in);
InStream_Dec_RefCount(self->ix_in);
}
- if (self->dat_in) {
- InStream_Close(self->dat_in);
+ if (self->dat_in) {
+ InStream_Close(self->dat_in);
InStream_Dec_RefCount(self->dat_in);
}
SUPER_DESTROY(self, TEXTSORTCACHE);
}
-#define NULL_SENTINEL -1
+#define NULL_SENTINEL -1
Obj*
-TextSortCache_value(TextSortCache *self, int32_t ord, Obj *blank)
-{
+TextSortCache_value(TextSortCache *self, int32_t ord, Obj *blank) {
if (ord == self->null_ord) {
return NULL;
}
InStream_Seek(self->ix_in, ord * sizeof(int64_t));
int64_t offset = InStream_Read_I64(self->ix_in);
- if (offset == NULL_SENTINEL) {
- return NULL;
+ if (offset == NULL_SENTINEL) {
+ return NULL;
}
else {
uint32_t next_ord = ord + 1;
@@ -123,8 +119,7 @@ TextSortCache_value(TextSortCache *self,
}
CharBuf*
-TextSortCache_make_blank(TextSortCache *self)
-{
+TextSortCache_make_blank(TextSortCache *self) {
UNUSED_VAR(self);
return CB_new_from_trusted_utf8("", 0);
}
Modified: incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortCache/TextSortCache.cfh Sun May 1 23:50:24 2011
@@ -18,7 +18,7 @@ parcel Lucy;
/** SortCache for TextType fields.
*/
-class Lucy::Index::SortCache::TextSortCache
+class Lucy::Index::SortCache::TextSortCache
inherits Lucy::Index::SortCache {
InStream *ord_in;
@@ -26,14 +26,14 @@ class Lucy::Index::SortCache::TextSortCa
InStream *dat_in;
inert incremented TextSortCache*
- new(const CharBuf *field, FieldType *type, int32_t cardinality,
- int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
+ new(const CharBuf *field, FieldType *type, int32_t cardinality,
+ int32_t doc_max, int32_t null_ord = -1, int32_t ord_width,
InStream *ord_in, InStream *ix_in, InStream *dat_in);
inert TextSortCache*
- init(TextSortCache *self, const CharBuf *field, FieldType *type,
+ init(TextSortCache *self, const CharBuf *field, FieldType *type,
int32_t cardinality, int32_t doc_max, int32_t null_ord = -1,
- int32_t ord_width, InStream *ord_in, InStream *ix_in,
+ int32_t ord_width, InStream *ord_in, InStream *ix_in,
InStream *dat_in);
public nullable Obj*
Modified: incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.c Sun May 1 23:50:24 2011
@@ -40,7 +40,7 @@
// Prepare to read back a run.
static void
-S_flip_run(SortFieldWriter *run, size_t sub_thresh, InStream *ord_in,
+S_flip_run(SortFieldWriter *run, size_t sub_thresh, InStream *ord_in,
InStream *ix_in, InStream *dat_in);
// Write out a sort cache. Returns the number of unique values in the sort
@@ -56,27 +56,25 @@ typedef struct lucy_SFWriterElem {
#define SFWriterElem lucy_SFWriterElem
SortFieldWriter*
-SortFieldWriter_new(Schema *schema, Snapshot *snapshot, Segment *segment,
+SortFieldWriter_new(Schema *schema, Snapshot *snapshot, Segment *segment,
PolyReader *polyreader, const CharBuf *field,
- MemoryPool *memory_pool, size_t mem_thresh,
- OutStream *temp_ord_out, OutStream *temp_ix_out,
- OutStream *temp_dat_out)
-{
- SortFieldWriter *self
+ MemoryPool *memory_pool, size_t mem_thresh,
+ OutStream *temp_ord_out, OutStream *temp_ix_out,
+ OutStream *temp_dat_out) {
+ SortFieldWriter *self
= (SortFieldWriter*)VTable_Make_Obj(SORTFIELDWRITER);
return SortFieldWriter_init(self, schema, snapshot, segment, polyreader,
- field, memory_pool, mem_thresh, temp_ord_out, temp_ix_out,
- temp_dat_out);
+ field, memory_pool, mem_thresh, temp_ord_out,
+ temp_ix_out, temp_dat_out);
}
SortFieldWriter*
-SortFieldWriter_init(SortFieldWriter *self, Schema *schema,
- Snapshot *snapshot, Segment *segment,
+SortFieldWriter_init(SortFieldWriter *self, Schema *schema,
+ Snapshot *snapshot, Segment *segment,
PolyReader *polyreader, const CharBuf *field,
- MemoryPool *memory_pool, size_t mem_thresh,
- OutStream *temp_ord_out, OutStream *temp_ix_out,
- OutStream *temp_dat_out)
-{
+ MemoryPool *memory_pool, size_t mem_thresh,
+ OutStream *temp_ord_out, OutStream *temp_ix_out,
+ OutStream *temp_dat_out) {
// Init.
SortEx_init((SortExternal*)self, sizeof(SFWriterElem));
self->null_ord = -1;
@@ -111,7 +109,7 @@ SortFieldWriter_init(SortFieldWriter *se
// Derive.
self->field_num = Seg_Field_Num(segment, field);
FieldType *type = (FieldType*)CERTIFY(
- Schema_Fetch_Type(self->schema, field), FIELDTYPE);
+ Schema_Fetch_Type(self->schema, field), FIELDTYPE);
self->type = (FieldType*)INCREF(type);
self->prim_id = FType_Primitive_ID(type);
if (self->prim_id == FType_TEXT || self->prim_id == FType_BLOB) {
@@ -126,20 +124,18 @@ SortFieldWriter_init(SortFieldWriter *se
}
void
-SortFieldWriter_clear_cache(SortFieldWriter *self)
-{
+SortFieldWriter_clear_cache(SortFieldWriter *self) {
if (self->uniq_vals) {
Hash_Clear(self->uniq_vals);
}
- SortFieldWriter_clear_cache_t super_clear_cache =
- (SortFieldWriter_clear_cache_t)SUPER_METHOD(self->vtable,
- SortFieldWriter, Clear_Cache);
+ SortFieldWriter_clear_cache_t super_clear_cache
+ = (SortFieldWriter_clear_cache_t)SUPER_METHOD(
+ self->vtable, SortFieldWriter, Clear_Cache);
super_clear_cache(self);
}
void
-SortFieldWriter_destroy(SortFieldWriter *self)
-{
+SortFieldWriter_destroy(SortFieldWriter *self) {
DECREF(self->uniq_vals);
self->uniq_vals = NULL;
DECREF(self->field);
@@ -162,25 +158,28 @@ SortFieldWriter_destroy(SortFieldWriter
}
int32_t
-SortFieldWriter_get_null_ord(SortFieldWriter *self) { return self->null_ord; }
+SortFieldWriter_get_null_ord(SortFieldWriter *self) {
+ return self->null_ord;
+}
+
int32_t
-SortFieldWriter_get_ord_width(SortFieldWriter *self) { return self->ord_width; }
+SortFieldWriter_get_ord_width(SortFieldWriter *self) {
+ return self->ord_width;
+}
static Obj*
-S_find_unique_value(Hash *uniq_vals, Obj *val)
-{
+S_find_unique_value(Hash *uniq_vals, Obj *val) {
int32_t hash_sum = Obj_Hash_Sum(val);
Obj *uniq_val = Hash_Find_Key(uniq_vals, val, hash_sum);
- if (!uniq_val) {
- Hash_Store(uniq_vals, val, INCREF(&EMPTY));
+ if (!uniq_val) {
+ Hash_Store(uniq_vals, val, INCREF(&EMPTY));
uniq_val = Hash_Find_Key(uniq_vals, val, hash_sum);
}
return uniq_val;
}
void
-SortFieldWriter_add(SortFieldWriter *self, int32_t doc_id, Obj *value)
-{
+SortFieldWriter_add(SortFieldWriter *self, int32_t doc_id, Obj *value) {
// Uniq-ify the value, and record it for this document.
SFWriterElem elem;
elem.value = S_find_unique_value(self->uniq_vals, value);
@@ -191,12 +190,12 @@ SortFieldWriter_add(SortFieldWriter *sel
void
SortFieldWriter_add_segment(SortFieldWriter *self, SegReader *reader,
- I32Array *doc_map, SortCache *sort_cache)
-{
+ I32Array *doc_map, SortCache *sort_cache) {
if (!sort_cache) { return; }
- SortFieldWriter *run = SortFieldWriter_new(self->schema, self->snapshot,
- self->segment, self->polyreader, self->field, self->mem_pool,
- self->mem_thresh, NULL, NULL, NULL);
+ SortFieldWriter *run
+ = SortFieldWriter_new(self->schema, self->snapshot, self->segment,
+ self->polyreader, self->field, self->mem_pool,
+ self->mem_thresh, NULL, NULL, NULL);
run->sort_cache = (SortCache*)INCREF(sort_cache);
run->doc_map = (I32Array*)INCREF(doc_map);
run->run_max = SegReader_Doc_Max(reader);
@@ -207,9 +206,8 @@ SortFieldWriter_add_segment(SortFieldWri
}
static int32_t
-S_calc_width(int32_t cardinality)
-{
- if (cardinality <= 0x00000002) { return 1; }
+S_calc_width(int32_t cardinality) {
+ if (cardinality <= 0x00000002) { return 1; }
else if (cardinality <= 0x00000004) { return 2; }
else if (cardinality <= 0x0000000F) { return 4; }
else if (cardinality <= 0x000000FF) { return 8; }
@@ -218,82 +216,82 @@ S_calc_width(int32_t cardinality)
}
static void
-S_write_ord(void *ords, int32_t width, int32_t doc_id, int32_t ord)
-{
+S_write_ord(void *ords, int32_t width, int32_t doc_id, int32_t ord) {
switch (width) {
- case 1: if (ord) { NumUtil_u1set(ords, doc_id); }
- else { NumUtil_u1clear(ords, doc_id); }
- break;
- case 2: NumUtil_u2set(ords, doc_id, ord);
- break;
- case 4: NumUtil_u4set(ords, doc_id, ord);
- break;
+ case 1:
+ if (ord) { NumUtil_u1set(ords, doc_id); }
+ else { NumUtil_u1clear(ords, doc_id); }
+ break;
+ case 2:
+ NumUtil_u2set(ords, doc_id, ord);
+ break;
+ case 4:
+ NumUtil_u4set(ords, doc_id, ord);
+ break;
case 8: {
- uint8_t *ints = (uint8_t*)ords;
- ints[doc_id] = ord;
- }
- break;
- case 16:
- {
- uint8_t *bytes = (uint8_t*)ords;
- bytes += doc_id * sizeof(uint16_t);
- NumUtil_encode_bigend_u16(ord, &bytes);
- }
- break;
- case 32:
- {
- uint8_t *bytes = (uint8_t*)ords;
- bytes += doc_id * sizeof(uint32_t);
- NumUtil_encode_bigend_u32(ord, &bytes);
- }
- break;
- default: THROW(ERR, "Invalid width: %i32", width);
+ uint8_t *ints = (uint8_t*)ords;
+ ints[doc_id] = ord;
+ }
+ break;
+ case 16: {
+ uint8_t *bytes = (uint8_t*)ords;
+ bytes += doc_id * sizeof(uint16_t);
+ NumUtil_encode_bigend_u16(ord, &bytes);
+ }
+ break;
+ case 32: {
+ uint8_t *bytes = (uint8_t*)ords;
+ bytes += doc_id * sizeof(uint32_t);
+ NumUtil_encode_bigend_u32(ord, &bytes);
+ }
+ break;
+ default:
+ THROW(ERR, "Invalid width: %i32", width);
}
}
static void
S_write_val(Obj *val, int8_t prim_id, OutStream *ix_out, OutStream *dat_out,
- int64_t dat_start)
-{
+ int64_t dat_start) {
if (val) {
switch (prim_id & FType_PRIMITIVE_ID_MASK) {
case FType_TEXT: {
- CharBuf *string = (CharBuf*)val;
- int64_t dat_pos = OutStream_Tell(dat_out) - dat_start;
- OutStream_Write_I64(ix_out, dat_pos);
- OutStream_Write_Bytes(dat_out, (char*)CB_Get_Ptr8(string),
- CB_Get_Size(string));
- break;
- }
+ CharBuf *string = (CharBuf*)val;
+ int64_t dat_pos = OutStream_Tell(dat_out) - dat_start;
+ OutStream_Write_I64(ix_out, dat_pos);
+ OutStream_Write_Bytes(dat_out, (char*)CB_Get_Ptr8(string),
+ CB_Get_Size(string));
+ break;
+ }
case FType_BLOB: {
- ByteBuf *byte_buf = (ByteBuf*)val;
- int64_t dat_pos = OutStream_Tell(dat_out) - dat_start;
- OutStream_Write_I64(ix_out, dat_pos);
- OutStream_Write_Bytes(dat_out, BB_Get_Buf(byte_buf),
- BB_Get_Size(byte_buf));
- break;
- }
+ ByteBuf *byte_buf = (ByteBuf*)val;
+ int64_t dat_pos = OutStream_Tell(dat_out) - dat_start;
+ OutStream_Write_I64(ix_out, dat_pos);
+ OutStream_Write_Bytes(dat_out, BB_Get_Buf(byte_buf),
+ BB_Get_Size(byte_buf));
+ break;
+ }
case FType_INT32: {
- Integer32 *i32 = (Integer32*)val;
- OutStream_Write_I32(dat_out, Int32_Get_Value(i32));
- break;
- }
+ Integer32 *i32 = (Integer32*)val;
+ OutStream_Write_I32(dat_out, Int32_Get_Value(i32));
+ break;
+ }
case FType_INT64: {
- Integer64 *i64 = (Integer64*)val;
- OutStream_Write_I64(dat_out, Int64_Get_Value(i64));
- break;
- }
+ Integer64 *i64 = (Integer64*)val;
+ OutStream_Write_I64(dat_out, Int64_Get_Value(i64));
+ break;
+ }
case FType_FLOAT64: {
- Float64 *float64 = (Float64*)val;
- OutStream_Write_F64(dat_out, Float64_Get_Value(float64));
- break;
- }
+ Float64 *float64 = (Float64*)val;
+ OutStream_Write_F64(dat_out, Float64_Get_Value(float64));
+ break;
+ }
case FType_FLOAT32: {
- Float32 *float32 = (Float32*)val;
- OutStream_Write_F32(dat_out, Float32_Get_Value(float32));
- break;
- }
- default:
+ Float32 *float32 = (Float32*)val;
+ OutStream_Write_F32(dat_out, Float32_Get_Value(float32));
+ break;
+ }
+ default:
THROW(ERR, "Unrecognized primitive id: %i32", (int32_t)prim_id);
}
}
@@ -305,10 +303,10 @@ S_write_val(Obj *val, int8_t prim_id, Ou
OutStream_Write_I64(ix_out, dat_pos);
}
break;
- case FType_INT32:
+ case FType_INT32:
OutStream_Write_I32(dat_out, 0);
break;
- case FType_INT64:
+ case FType_INT64:
OutStream_Write_I64(dat_out, 0);
break;
case FType_FLOAT64:
@@ -317,26 +315,24 @@ S_write_val(Obj *val, int8_t prim_id, Ou
case FType_FLOAT32:
OutStream_Write_F32(dat_out, 0.0f);
break;
- default:
+ default:
THROW(ERR, "Unrecognized primitive id: %i32", (int32_t)prim_id);
}
}
}
int
-SortFieldWriter_compare(SortFieldWriter *self, void *va, void *vb)
-{
+SortFieldWriter_compare(SortFieldWriter *self, void *va, void *vb) {
SFWriterElem *a = (SFWriterElem*)va;
SFWriterElem *b = (SFWriterElem*)vb;
- int32_t comparison
+ int32_t comparison
= FType_null_back_compare_values(self->type, a->value, b->value);
if (comparison == 0) { comparison = b->doc_id - a->doc_id; }
return comparison;
}
static int
-S_compare_doc_ids_by_ord_rev(void *context, const void *va, const void *vb)
-{
+S_compare_doc_ids_by_ord_rev(void *context, const void *va, const void *vb) {
SortCache *sort_cache = (SortCache*)context;
int32_t a = *(int32_t*)va;
int32_t b = *(int32_t*)vb;
@@ -346,22 +342,20 @@ S_compare_doc_ids_by_ord_rev(void *conte
}
static void
-S_lazy_init_sorted_ids(SortFieldWriter *self)
-{
+S_lazy_init_sorted_ids(SortFieldWriter *self) {
if (!self->sorted_ids) {
- self->sorted_ids
+ self->sorted_ids
= (int32_t*)MALLOCATE((self->run_max + 1) * sizeof(int32_t));
for (int32_t i = 0, max = self->run_max; i <= max; i++) {
self->sorted_ids[i] = i;
}
- Sort_quicksort(self->sorted_ids + 1, self->run_max, sizeof(int32_t),
- S_compare_doc_ids_by_ord_rev, self->sort_cache);
+ Sort_quicksort(self->sorted_ids + 1, self->run_max, sizeof(int32_t),
+ S_compare_doc_ids_by_ord_rev, self->sort_cache);
}
}
void
-SortFieldWriter_flush(SortFieldWriter *self)
-{
+SortFieldWriter_flush(SortFieldWriter *self) {
// Don't add a run unless we have data to put in it.
if (SortFieldWriter_Cache_Count(self) == 0) { return; }
@@ -370,9 +364,10 @@ SortFieldWriter_flush(SortFieldWriter *s
OutStream *const temp_dat_out = self->temp_dat_out;
SortFieldWriter_Sort_Cache(self);
- SortFieldWriter *run = SortFieldWriter_new(self->schema, self->snapshot,
- self->segment, self->polyreader, self->field, self->mem_pool,
- self->mem_thresh, NULL, NULL, NULL);
+ SortFieldWriter *run
+ = SortFieldWriter_new(self->schema, self->snapshot, self->segment,
+ self->polyreader, self->field, self->mem_pool,
+ self->mem_thresh, NULL, NULL, NULL);
// Record stream starts and align.
run->ord_start = OutStream_Align(temp_ord_out, sizeof(int64_t));
@@ -390,7 +385,7 @@ SortFieldWriter_flush(SortFieldWriter *s
// Write files, record stats.
run->run_max = (int32_t)Seg_Get_Count(self->segment);
run->run_cardinality = S_write_files(run, temp_ord_out, temp_ix_out,
- temp_dat_out);
+ temp_dat_out);
// Reclaim the buffer from the run and empty it.
run->cache = NULL;
@@ -412,15 +407,14 @@ SortFieldWriter_flush(SortFieldWriter *s
}
uint32_t
-SortFieldWriter_refill(SortFieldWriter *self)
-{
+SortFieldWriter_refill(SortFieldWriter *self) {
if (!self->sort_cache) { return 0; }
// Sanity check, then reset the cache and prepare to start loading items.
uint32_t cache_count = SortFieldWriter_Cache_Count(self);
if (cache_count) {
THROW(ERR, "Refill called but cache contains %u32 items",
- cache_count);
+ cache_count);
}
SortFieldWriter_Clear_Cache(self);
MemPool_Release_All(self->mem_pool);
@@ -432,9 +426,9 @@ SortFieldWriter_refill(SortFieldWriter *
SortCache *const sort_cache = self->sort_cache;
Obj *const blank = SortCache_Make_Blank(sort_cache);
- while ( self->run_ord < self->run_cardinality
+ while (self->run_ord < self->run_cardinality
&& MemPool_Get_Consumed(self->mem_pool) < self->mem_thresh
- ) {
+ ) {
Obj *val = SortCache_Value(sort_cache, self->run_ord, blank);
if (val) {
Hash_Store(uniq_vals, val, INCREF(&EMPTY));
@@ -447,8 +441,9 @@ SortFieldWriter_refill(SortFieldWriter *
int32_t raw_doc_id = self->sorted_ids[self->run_tick];
int32_t ord = SortCache_Ordinal(sort_cache, raw_doc_id);
if (ord != null_ord) {
- int32_t remapped = doc_map
- ? I32Arr_Get(doc_map, raw_doc_id) : raw_doc_id;
+ int32_t remapped = doc_map
+ ? I32Arr_Get(doc_map, raw_doc_id)
+ : raw_doc_id;
if (remapped) {
Obj *val = SortCache_Value(sort_cache, ord, blank);
SortFieldWriter_Add(self, remapped, val);
@@ -473,8 +468,7 @@ SortFieldWriter_refill(SortFieldWriter *
}
void
-SortFieldWriter_flip(SortFieldWriter *self)
-{
+SortFieldWriter_flip(SortFieldWriter *self) {
uint32_t num_items = SortFieldWriter_Cache_Count(self);
uint32_t num_runs = VA_Get_Size(self->runs);
@@ -484,7 +478,7 @@ SortFieldWriter_flip(SortFieldWriter *se
// Sanity check.
if (num_runs && num_items) {
THROW(ERR, "Sanity check failed: num_runs: %u32 num_items: %u32",
- num_runs, num_items);
+ num_runs, num_items);
}
if (num_items) {
@@ -511,8 +505,8 @@ SortFieldWriter_flip(SortFieldWriter *se
if (sub_thresh < 65536) { sub_thresh = 65536; }
for (uint32_t i = 0; i < num_runs; i++) {
SortFieldWriter *run = (SortFieldWriter*)VA_Fetch(self->runs, i);
- S_flip_run(run, sub_thresh, self->ord_in, self->ix_in,
- self->dat_in);
+ S_flip_run(run, sub_thresh, self->ord_in, self->ix_in,
+ self->dat_in);
}
}
@@ -521,8 +515,7 @@ SortFieldWriter_flip(SortFieldWriter *se
static int32_t
S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
- OutStream *dat_out)
-{
+ OutStream *dat_out) {
int8_t prim_id = self->prim_id;
int32_t doc_max = (int32_t)Seg_Get_Count(self->segment);
bool_t has_nulls = self->count == doc_max ? false : true;
@@ -548,10 +541,10 @@ S_write_files(SortFieldWriter *self, Out
S_write_val(elem->value, prim_id, ix_out, dat_out, dat_start);
while (NULL != (elem = (SFWriterElem*)SortFieldWriter_Fetch(self))) {
if (elem->value != last_val_address) {
- int32_t comparison = FType_Compare_Values(self->type,
- elem->value, val);
+ int32_t comparison
+ = FType_Compare_Values(self->type, elem->value, val);
if (comparison != 0) {
- ord++;
+ ord++;
S_write_val(elem->value, prim_id, ix_out, dat_out, dat_start);
Obj_Mimic(val, elem->value);
}
@@ -583,12 +576,12 @@ S_write_files(SortFieldWriter *self, Out
const double BITS_PER_BYTE = 8.0;
double bytes_per_doc = ord_width / BITS_PER_BYTE;
double byte_count = ceil((doc_max + 1) * bytes_per_doc);
- char *compressed_ords
+ char *compressed_ords
= (char*)CALLOCATE((size_t)byte_count, sizeof(char));
for (int32_t i = 0; i <= doc_max; i++) {
int32_t real_ord = ords[i] == -1 ? null_ord : ords[i];
S_write_ord(compressed_ords, ord_width, i, real_ord);
- }
+ }
OutStream_Write_Bytes(ord_out, compressed_ords, (size_t)byte_count);
FREEMEM(compressed_ords);
@@ -597,8 +590,7 @@ S_write_files(SortFieldWriter *self, Out
}
int32_t
-SortFieldWriter_finish(SortFieldWriter *self)
-{
+SortFieldWriter_finish(SortFieldWriter *self) {
// Bail if there's no data.
if (!SortFieldWriter_Peek(self)) { return 0; }
@@ -635,9 +627,8 @@ SortFieldWriter_finish(SortFieldWriter *
}
static void
-S_flip_run(SortFieldWriter *run, size_t sub_thresh, InStream *ord_in,
- InStream *ix_in, InStream *dat_in)
-{
+S_flip_run(SortFieldWriter *run, size_t sub_thresh, InStream *ord_in,
+ InStream *ix_in, InStream *dat_in) {
if (run->flipped) { THROW(ERR, "Can't Flip twice"); }
run->flipped = true;
@@ -653,50 +644,60 @@ S_flip_run(SortFieldWriter *run, size_t
// Open the temp files for reading.
CharBuf *seg_name = Seg_Get_Name(run->segment);
- CharBuf *alias = CB_newf("%o/sort_ord_temp-%i64-to-%i64", seg_name,
- run->ord_start, run->ord_end);
- InStream *ord_in_dupe = InStream_Reopen(ord_in, alias,
- run->ord_start, run->ord_end - run->ord_start);
+ CharBuf *alias = CB_newf("%o/sort_ord_temp-%i64-to-%i64", seg_name,
+ run->ord_start, run->ord_end);
+ InStream *ord_in_dupe = InStream_Reopen(ord_in, alias, run->ord_start,
+ run->ord_end - run->ord_start);
InStream *ix_in_dupe = NULL;
if (run->var_width) {
- CB_setf(alias, "%o/sort_ix_temp-%i64-to-%i64", seg_name,
- run->ix_start, run->ix_end);
- ix_in_dupe = InStream_Reopen(ix_in, alias,
- run->ix_start, run->ix_end - run->ix_start);
- }
- CB_setf(alias, "%o/sort_dat_temp-%i64-to-%i64", seg_name,
- run->dat_start, run->dat_end);
- InStream *dat_in_dupe = InStream_Reopen(dat_in, alias,
- run->dat_start, run->dat_end - run->dat_start);
+ CB_setf(alias, "%o/sort_ix_temp-%i64-to-%i64", seg_name,
+ run->ix_start, run->ix_end);
+ ix_in_dupe = InStream_Reopen(ix_in, alias, run->ix_start,
+ run->ix_end - run->ix_start);
+ }
+ CB_setf(alias, "%o/sort_dat_temp-%i64-to-%i64", seg_name,
+ run->dat_start, run->dat_end);
+ InStream *dat_in_dupe = InStream_Reopen(dat_in, alias, run->dat_start,
+ run->dat_end - run->dat_start);
DECREF(alias);
// Get a SortCache.
CharBuf *field = Seg_Field_Name(run->segment, run->field_num);
switch (run->prim_id & FType_PRIMITIVE_ID_MASK) {
case FType_TEXT:
- run->sort_cache = (SortCache*)TextSortCache_new(field,
- run->type, run->run_cardinality, run->run_max, run->null_ord,
- run->ord_width, ord_in_dupe, ix_in_dupe, dat_in_dupe);
+ run->sort_cache = (SortCache*)TextSortCache_new(
+ field, run->type, run->run_cardinality,
+ run->run_max, run->null_ord,
+ run->ord_width, ord_in_dupe,
+ ix_in_dupe, dat_in_dupe);
break;
case FType_INT32:
- run->sort_cache = (SortCache*)I32SortCache_new(field,
- run->type, run->run_cardinality, run->run_max, run->null_ord,
- run->ord_width, ord_in_dupe, dat_in_dupe);
+ run->sort_cache = (SortCache*)I32SortCache_new(
+ field, run->type, run->run_cardinality,
+ run->run_max, run->null_ord,
+ run->ord_width, ord_in_dupe,
+ dat_in_dupe);
break;
case FType_INT64:
- run->sort_cache = (SortCache*)I64SortCache_new(field,
- run->type, run->run_cardinality, run->run_max, run->null_ord,
- run->ord_width, ord_in_dupe, dat_in_dupe);
+ run->sort_cache = (SortCache*)I64SortCache_new(
+ field, run->type, run->run_cardinality,
+ run->run_max, run->null_ord,
+ run->ord_width, ord_in_dupe,
+ dat_in_dupe);
break;
case FType_FLOAT32:
- run->sort_cache = (SortCache*)F32SortCache_new(field,
- run->type, run->run_cardinality, run->run_max, run->null_ord,
- run->ord_width, ord_in_dupe, dat_in_dupe);
+ run->sort_cache = (SortCache*)F32SortCache_new(
+ field, run->type, run->run_cardinality,
+ run->run_max, run->null_ord,
+ run->ord_width, ord_in_dupe,
+ dat_in_dupe);
break;
case FType_FLOAT64:
- run->sort_cache = (SortCache*)F64SortCache_new(field,
- run->type, run->run_cardinality, run->run_max, run->null_ord,
- run->ord_width, ord_in_dupe, dat_in_dupe);
+ run->sort_cache = (SortCache*)F64SortCache_new(
+ field, run->type, run->run_cardinality,
+ run->run_max, run->null_ord,
+ run->ord_width, ord_in_dupe,
+ dat_in_dupe);
break;
default:
THROW(ERR, "No SortCache class for %o", run->type);
Modified: incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortFieldWriter.cfh Sun May 1 23:50:24 2011
@@ -16,7 +16,7 @@
parcel Lucy;
-class Lucy::Index::SortFieldWriter
+class Lucy::Index::SortFieldWriter
inherits Lucy::Util::SortExternal {
CharBuf *field;
Hash *uniq_vals;
@@ -53,22 +53,22 @@ class Lucy::Index::SortFieldWriter
int32_t ord_width;
inert incremented SortFieldWriter*
- new(Schema *schema, Snapshot *snapshot, Segment *segment,
+ new(Schema *schema, Snapshot *snapshot, Segment *segment,
PolyReader *polyreader, const CharBuf *field, MemoryPool *memory_pool,
size_t mem_thresh, OutStream *temp_ord_out, OutStream *temp_ix_out,
OutStream *temp_dat_out);
inert SortFieldWriter*
- init(SortFieldWriter *self, Schema *schema, Snapshot *snapshot,
+ init(SortFieldWriter *self, Schema *schema, Snapshot *snapshot,
Segment *segment, PolyReader *polyreader, const CharBuf *field,
- MemoryPool *memory_pool, size_t mem_thresh, OutStream *temp_ord_out,
+ MemoryPool *memory_pool, size_t mem_thresh, OutStream *temp_ord_out,
OutStream *temp_ix_out, OutStream *temp_dat_out);
void
Add(SortFieldWriter *self, int32_t doc_id, Obj *value);
void
- Add_Segment(SortFieldWriter *self, SegReader *reader, I32Array *doc_map,
+ Add_Segment(SortFieldWriter *self, SegReader *reader, I32Array *doc_map,
SortCache *sort_cache);
void
Modified: incubator/lucy/trunk/core/Lucy/Index/SortReader.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortReader.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortReader.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortReader.c Sun May 1 23:50:24 2011
@@ -31,17 +31,15 @@
SortReader*
SortReader_init(SortReader *self, Schema *schema, Folder *folder,
- Snapshot *snapshot, VArray *segments, int32_t seg_tick)
-{
+ Snapshot *snapshot, VArray *segments, int32_t seg_tick) {
DataReader_init((DataReader*)self, schema, folder, snapshot, segments,
- seg_tick);
+ seg_tick);
ABSTRACT_CLASS_CHECK(self, SORTREADER);
return self;
}
DataReader*
-SortReader_aggregator(SortReader *self, VArray *readers, I32Array *offsets)
-{
+SortReader_aggregator(SortReader *self, VArray *readers, I32Array *offsets) {
UNUSED_VAR(self);
UNUSED_VAR(readers);
UNUSED_VAR(offsets);
@@ -49,26 +47,24 @@ SortReader_aggregator(SortReader *self,
}
DefaultSortReader*
-DefSortReader_new(Schema *schema, Folder *folder, Snapshot *snapshot,
- VArray *segments, int32_t seg_tick)
-{
- DefaultSortReader *self
+DefSortReader_new(Schema *schema, Folder *folder, Snapshot *snapshot,
+ VArray *segments, int32_t seg_tick) {
+ DefaultSortReader *self
= (DefaultSortReader*)VTable_Make_Obj(DEFAULTSORTREADER);
return DefSortReader_init(self, schema, folder, snapshot, segments,
- seg_tick);
+ seg_tick);
}
DefaultSortReader*
DefSortReader_init(DefaultSortReader *self, Schema *schema, Folder *folder,
- Snapshot *snapshot, VArray *segments, int32_t seg_tick)
-{
+ Snapshot *snapshot, VArray *segments, int32_t seg_tick) {
Segment *segment;
Hash *metadata;
DataReader_init((DataReader*)self, schema, folder, snapshot, segments,
- seg_tick);
+ seg_tick);
segment = DefSortReader_Get_Segment(self);
metadata = (Hash*)Seg_Fetch_Metadata_Str(segment, "sort", 4);
-
+
// Check format.
self->format = 0;
if (metadata) {
@@ -78,7 +74,7 @@ DefSortReader_init(DefaultSortReader *se
self->format = (int32_t)Obj_To_I64(format);
if (self->format < 2 || self->format > 3) {
THROW(ERR, "Unsupported sort cache format: %i32",
- self->format);
+ self->format);
}
}
}
@@ -89,8 +85,9 @@ DefSortReader_init(DefaultSortReader *se
// Either extract or fake up the "counts", "null_ords", and "ord_widths"
// hashes.
if (metadata) {
- self->counts = (Hash*)INCREF(CERTIFY(
- Hash_Fetch_Str(metadata, "counts", 6), HASH));
+ self->counts
+ = (Hash*)INCREF(CERTIFY(Hash_Fetch_Str(metadata, "counts", 6),
+ HASH));
self->null_ords = (Hash*)Hash_Fetch_Str(metadata, "null_ords", 9);
if (self->null_ords) {
CERTIFY(self->null_ords, HASH);
@@ -118,8 +115,7 @@ DefSortReader_init(DefaultSortReader *se
}
void
-DefSortReader_close(DefaultSortReader *self)
-{
+DefSortReader_close(DefaultSortReader *self) {
if (self->caches) {
Hash_Dec_RefCount(self->caches);
self->caches = NULL;
@@ -139,8 +135,7 @@ DefSortReader_close(DefaultSortReader *s
}
void
-DefSortReader_destroy(DefaultSortReader *self)
-{
+DefSortReader_destroy(DefaultSortReader *self) {
DECREF(self->caches);
DECREF(self->counts);
DECREF(self->null_ords);
@@ -149,9 +144,8 @@ DefSortReader_destroy(DefaultSortReader
}
static int32_t
-S_calc_ord_width(int32_t cardinality)
-{
- if (cardinality <= 0x00000002) { return 1; }
+S_calc_ord_width(int32_t cardinality) {
+ if (cardinality <= 0x00000002) { return 1; }
else if (cardinality <= 0x00000004) { return 2; }
else if (cardinality <= 0x0000000F) { return 4; }
else if (cardinality <= 0x000000FF) { return 8; }
@@ -160,8 +154,7 @@ S_calc_ord_width(int32_t cardinality)
}
static SortCache*
-S_lazy_init_sort_cache(DefaultSortReader *self, const CharBuf *field)
-{
+S_lazy_init_sort_cache(DefaultSortReader *self, const CharBuf *field) {
// See if we have any values.
Obj *count_obj = Hash_Fetch(self->counts, (Obj*)field);
int32_t count = count_obj ? (int32_t)Obj_To_I64(count_obj) : 0;
@@ -182,14 +175,14 @@ S_lazy_init_sort_cache(DefaultSortReader
int32_t field_num = Seg_Field_Num(segment, field);
int8_t prim_id = FType_Primitive_ID(type);
bool_t var_width = (prim_id == FType_TEXT || prim_id == FType_BLOB)
- ? true
- : false;
+ ? true
+ : false;
CB_setf(path, "%o/sort-%i32.ord", seg_name, field_num);
InStream *ord_in = Folder_Open_In(folder, path);
if (!ord_in) {
DECREF(path);
- THROW(ERR, "Error building sort cache for '%o': %o",
- field, Err_get_error());
+ THROW(ERR, "Error building sort cache for '%o': %o",
+ field, Err_get_error());
}
InStream *ix_in = NULL;
if (var_width) {
@@ -197,48 +190,53 @@ S_lazy_init_sort_cache(DefaultSortReader
ix_in = Folder_Open_In(folder, path);
if (!ix_in) {
DECREF(path);
- THROW(ERR, "Error building sort cache for '%o': %o",
- field, Err_get_error());
+ THROW(ERR, "Error building sort cache for '%o': %o",
+ field, Err_get_error());
}
}
CB_setf(path, "%o/sort-%i32.dat", seg_name, field_num);
InStream *dat_in = Folder_Open_In(folder, path);
if (!dat_in) {
DECREF(path);
- THROW(ERR, "Error building sort cache for '%o': %o",
- field, Err_get_error());
+ THROW(ERR, "Error building sort cache for '%o': %o",
+ field, Err_get_error());
}
DECREF(path);
Obj *null_ord_obj = Hash_Fetch(self->null_ords, (Obj*)field);
int32_t null_ord = null_ord_obj ? (int32_t)Obj_To_I64(null_ord_obj) : -1;
Obj *ord_width_obj = Hash_Fetch(self->ord_widths, (Obj*)field);
- int32_t ord_width = ord_width_obj
- ? (int32_t)Obj_To_I64(ord_width_obj)
- : S_calc_ord_width(count);
+ int32_t ord_width = ord_width_obj
+ ? (int32_t)Obj_To_I64(ord_width_obj)
+ : S_calc_ord_width(count);
int32_t doc_max = (int32_t)Seg_Get_Count(segment);
SortCache *cache = NULL;
switch (prim_id & FType_PRIMITIVE_ID_MASK) {
case FType_TEXT:
- cache = (SortCache*)TextSortCache_new(field, type, count,
- doc_max, null_ord, ord_width, ord_in, ix_in, dat_in);
+ cache = (SortCache*)TextSortCache_new(field, type, count, doc_max,
+ null_ord, ord_width, ord_in,
+ ix_in, dat_in);
break;
case FType_INT32:
- cache = (SortCache*)I32SortCache_new(field, type, count,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ cache = (SortCache*)I32SortCache_new(field, type, count, doc_max,
+ null_ord, ord_width, ord_in,
+ dat_in);
break;
case FType_INT64:
- cache = (SortCache*)I64SortCache_new(field, type, count,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ cache = (SortCache*)I64SortCache_new(field, type, count, doc_max,
+ null_ord, ord_width, ord_in,
+ dat_in);
break;
case FType_FLOAT32:
- cache = (SortCache*)F32SortCache_new(field, type, count,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ cache = (SortCache*)F32SortCache_new(field, type, count, doc_max,
+ null_ord, ord_width, ord_in,
+ dat_in);
break;
case FType_FLOAT64:
- cache = (SortCache*)F64SortCache_new(field, type, count,
- doc_max, null_ord, ord_width, ord_in, dat_in);
+ cache = (SortCache*)F64SortCache_new(field, type, count, doc_max,
+ null_ord, ord_width, ord_in,
+ dat_in);
break;
default:
THROW(ERR, "No SortCache class for %o", type);
@@ -257,8 +255,7 @@ S_lazy_init_sort_cache(DefaultSortReader
}
SortCache*
-DefSortReader_fetch_sort_cache(DefaultSortReader *self, const CharBuf *field)
-{
+DefSortReader_fetch_sort_cache(DefaultSortReader *self, const CharBuf *field) {
SortCache *cache = NULL;
if (field) {
Modified: incubator/lucy/trunk/core/Lucy/Index/SortReader.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortReader.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortReader.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortReader.cfh Sun May 1 23:50:24 2011
@@ -18,7 +18,7 @@ parcel Lucy;
/** Read a segment's sort caches.
*/
-abstract class Lucy::Index::SortReader
+abstract class Lucy::Index::SortReader
inherits Lucy::Index::DataReader {
inert SortReader*
@@ -34,10 +34,10 @@ abstract class Lucy::Index::SortReader
*/
public incremented nullable DataReader*
Aggregator(SortReader *self, VArray *readers, I32Array *offsets);
-
+
}
-class Lucy::Index::DefaultSortReader cnick DefSortReader
+class Lucy::Index::DefaultSortReader cnick DefSortReader
inherits Lucy::Index::SortReader {
Hash *caches;
@@ -51,7 +51,7 @@ class Lucy::Index::DefaultSortReader cni
int32_t seg_tick);
inert DefaultSortReader*
- init(DefaultSortReader *self, Schema *schema, Folder *folder,
+ init(DefaultSortReader *self, Schema *schema, Folder *folder,
Snapshot *snapshot, VArray *segments, int32_t seg_tick);
nullable SortCache*
Modified: incubator/lucy/trunk/core/Lucy/Index/SortWriter.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortWriter.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortWriter.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortWriter.c Sun May 1 23:50:24 2011
@@ -42,16 +42,14 @@ static size_t default_mem_thresh = 0x400
SortWriter*
SortWriter_new(Schema *schema, Snapshot *snapshot, Segment *segment,
- PolyReader *polyreader)
-{
+ PolyReader *polyreader) {
SortWriter *self = (SortWriter*)VTable_Make_Obj(SORTWRITER);
return SortWriter_init(self, schema, snapshot, segment, polyreader);
}
SortWriter*
SortWriter_init(SortWriter *self, Schema *schema, Snapshot *snapshot,
- Segment *segment, PolyReader *polyreader)
-{
+ Segment *segment, PolyReader *polyreader) {
uint32_t field_max = Schema_Num_Fields(schema) + 1;
DataWriter_init((DataWriter*)self, schema, snapshot, segment, polyreader);
@@ -71,8 +69,7 @@ SortWriter_init(SortWriter *self, Schema
}
void
-SortWriter_destroy(SortWriter *self)
-{
+SortWriter_destroy(SortWriter *self) {
DECREF(self->field_writers);
DECREF(self->counts);
DECREF(self->null_ords);
@@ -85,15 +82,13 @@ SortWriter_destroy(SortWriter *self)
}
void
-SortWriter_set_default_mem_thresh(size_t mem_thresh)
-{
+SortWriter_set_default_mem_thresh(size_t mem_thresh) {
default_mem_thresh = mem_thresh;
}
static SortFieldWriter*
-S_lazy_init_field_writer(SortWriter *self, int32_t field_num)
-{
- SortFieldWriter *field_writer
+S_lazy_init_field_writer(SortWriter *self, int32_t field_num) {
+ SortFieldWriter *field_writer
= (SortFieldWriter*)VA_Fetch(self->field_writers, field_num);
if (!field_writer) {
@@ -103,19 +98,19 @@ S_lazy_init_field_writer(SortWriter *sel
CharBuf *seg_name = Seg_Get_Name(self->segment);
CharBuf *path = CB_newf("%o/sort_ord_temp", seg_name);
self->temp_ord_out = Folder_Open_Out(folder, path);
- if (!self->temp_ord_out) {
+ if (!self->temp_ord_out) {
DECREF(path);
- RETHROW(INCREF(Err_get_error()));
+ RETHROW(INCREF(Err_get_error()));
}
CB_setf(path, "%o/sort_ix_temp", seg_name);
self->temp_ix_out = Folder_Open_Out(folder, path);
- if (!self->temp_ix_out) {
+ if (!self->temp_ix_out) {
DECREF(path);
- RETHROW(INCREF(Err_get_error()));
+ RETHROW(INCREF(Err_get_error()));
}
CB_setf(path, "%o/sort_dat_temp", seg_name);
self->temp_dat_out = Folder_Open_Out(folder, path);
- if (!self->temp_dat_out) {
+ if (!self->temp_dat_out) {
DECREF(path);
RETHROW(INCREF(Err_get_error()));
}
@@ -123,29 +118,29 @@ S_lazy_init_field_writer(SortWriter *sel
}
CharBuf *field = Seg_Field_Name(self->segment, field_num);
- field_writer = SortFieldWriter_new(self->schema, self->snapshot,
- self->segment, self->polyreader, field, self->mem_pool,
- self->mem_thresh, self->temp_ord_out, self->temp_ix_out,
- self->temp_dat_out);
+ field_writer
+ = SortFieldWriter_new(self->schema, self->snapshot, self->segment,
+ self->polyreader, field, self->mem_pool,
+ self->mem_thresh, self->temp_ord_out,
+ self->temp_ix_out, self->temp_dat_out);
VA_Store(self->field_writers, field_num, (Obj*)field_writer);
}
return field_writer;
}
void
-SortWriter_add_inverted_doc(SortWriter *self, Inverter *inverter,
- int32_t doc_id)
-{
+SortWriter_add_inverted_doc(SortWriter *self, Inverter *inverter,
+ int32_t doc_id) {
int32_t field_num;
Inverter_Iterate(inverter);
while (0 != (field_num = Inverter_Next(inverter))) {
FieldType *type = Inverter_Get_Type(inverter);
if (FType_Sortable(type)) {
- SortFieldWriter *field_writer
+ SortFieldWriter *field_writer
= S_lazy_init_field_writer(self, field_num);
SortFieldWriter_Add(field_writer, doc_id,
- Inverter_Get_Value(inverter));
+ Inverter_Get_Value(inverter));
}
}
@@ -153,7 +148,7 @@ SortWriter_add_inverted_doc(SortWriter *
// flush all of them, then release all unique values with a single action.
if (MemPool_Get_Consumed(self->mem_pool) > self->mem_thresh) {
for (uint32_t i = 0; i < VA_Get_Size(self->field_writers); i++) {
- SortFieldWriter *const field_writer
+ SortFieldWriter *const field_writer
= (SortFieldWriter*)VA_Fetch(self->field_writers, i);
if (field_writer) { SortFieldWriter_Flush(field_writer); }
}
@@ -163,20 +158,21 @@ SortWriter_add_inverted_doc(SortWriter *
}
void
-SortWriter_add_segment(SortWriter *self, SegReader *reader, I32Array *doc_map)
-{
- VArray *fields = Schema_All_Fields(self->schema);
+SortWriter_add_segment(SortWriter *self, SegReader *reader,
+ I32Array *doc_map) {
+ VArray *fields = Schema_All_Fields(self->schema);
// Proceed field-at-a-time, rather than doc-at-a-time.
for (uint32_t i = 0, max = VA_Get_Size(fields); i < max; i++) {
CharBuf *field = (CharBuf*)VA_Fetch(fields, i);
- SortReader *sort_reader = (SortReader*)SegReader_Fetch(reader,
- VTable_Get_Name(SORTREADER));
- SortCache *cache = sort_reader
- ? SortReader_Fetch_Sort_Cache(sort_reader, field) : NULL;
+ SortReader *sort_reader = (SortReader*)SegReader_Fetch(
+ reader, VTable_Get_Name(SORTREADER));
+ SortCache *cache = sort_reader
+ ? SortReader_Fetch_Sort_Cache(sort_reader, field)
+ : NULL;
if (cache) {
int32_t field_num = Seg_Field_Num(self->segment, field);
- SortFieldWriter *field_writer
+ SortFieldWriter *field_writer
= S_lazy_init_field_writer(self, field_num);
SortFieldWriter_Add_Segment(field_writer, reader, doc_map, cache);
self->flush_at_finish = true;
@@ -187,8 +183,7 @@ SortWriter_add_segment(SortWriter *self,
}
void
-SortWriter_finish(SortWriter *self)
-{
+SortWriter_finish(SortWriter *self) {
VArray *const field_writers = self->field_writers;
// If we have no data, bail out.
@@ -198,7 +193,7 @@ SortWriter_finish(SortWriter *self)
// one field can use the entire margin up to mem_thresh.
if (self->flush_at_finish) {
for (uint32_t i = 1, max = VA_Get_Size(field_writers); i < max; i++) {
- SortFieldWriter *field_writer
+ SortFieldWriter *field_writer
= (SortFieldWriter*)VA_Fetch(field_writers, i);
if (field_writer) {
SortFieldWriter_Flush(field_writer);
@@ -212,22 +207,22 @@ SortWriter_finish(SortWriter *self)
OutStream_Close(self->temp_dat_out);
for (uint32_t i = 1, max = VA_Get_Size(field_writers); i < max; i++) {
- SortFieldWriter *field_writer
+ SortFieldWriter *field_writer
= (SortFieldWriter*)VA_Delete(field_writers, i);
if (field_writer) {
CharBuf *field = Seg_Field_Name(self->segment, i);
SortFieldWriter_Flip(field_writer);
int32_t count = SortFieldWriter_Finish(field_writer);
- Hash_Store(self->counts, (Obj*)field,
- (Obj*)CB_newf("%i32", count));
+ Hash_Store(self->counts, (Obj*)field,
+ (Obj*)CB_newf("%i32", count));
int32_t null_ord = SortFieldWriter_Get_Null_Ord(field_writer);
if (null_ord != -1) {
- Hash_Store(self->null_ords, (Obj*)field,
- (Obj*)CB_newf("%i32", null_ord));
+ Hash_Store(self->null_ords, (Obj*)field,
+ (Obj*)CB_newf("%i32", null_ord));
}
int32_t ord_width = SortFieldWriter_Get_Ord_Width(field_writer);
- Hash_Store(self->ord_widths, (Obj*)field,
- (Obj*)CB_newf("%i32", ord_width));
+ Hash_Store(self->ord_widths, (Obj*)field,
+ (Obj*)CB_newf("%i32", ord_width));
}
DECREF(field_writer);
@@ -236,7 +231,7 @@ SortWriter_finish(SortWriter *self)
// Store metadata.
Seg_Store_Metadata_Str(self->segment, "sort", 4,
- (Obj*)SortWriter_Metadata(self));
+ (Obj*)SortWriter_Metadata(self));
// Clean up.
Folder *folder = self->folder;
@@ -251,8 +246,7 @@ SortWriter_finish(SortWriter *self)
}
Hash*
-SortWriter_metadata(SortWriter *self)
-{
+SortWriter_metadata(SortWriter *self) {
Hash *const metadata = DataWriter_metadata((DataWriter*)self);
Hash_Store_Str(metadata, "counts", 6, INCREF(self->counts));
Hash_Store_Str(metadata, "null_ords", 9, INCREF(self->null_ords));
@@ -261,8 +255,7 @@ SortWriter_metadata(SortWriter *self)
}
int32_t
-SortWriter_format(SortWriter *self)
-{
+SortWriter_format(SortWriter *self) {
UNUSED_VAR(self);
return SortWriter_current_file_format;
}
Modified: incubator/lucy/trunk/core/Lucy/Index/SortWriter.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/SortWriter.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/SortWriter.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Index/SortWriter.cfh Sun May 1 23:50:24 2011
@@ -36,7 +36,7 @@ class Lucy::Index::SortWriter inherits L
OutStream *temp_ix_out;
OutStream *temp_dat_out;
MemoryPool *mem_pool;
- size_t mem_thresh;
+ size_t mem_thresh;
bool_t flush_at_finish;
inert int32_t current_file_format;
@@ -45,7 +45,7 @@ class Lucy::Index::SortWriter inherits L
new(Schema *schema, Snapshot *snapshot, Segment *segment,
PolyReader *polyreader);
- inert SortWriter*
+ inert SortWriter*
init(SortWriter *self, Schema *schema, Snapshot *snapshot,
Segment *segment, PolyReader *polyreader);
@@ -57,8 +57,8 @@ class Lucy::Index::SortWriter inherits L
Add_Inverted_Doc(SortWriter *self, Inverter *inverter, int32_t doc_id);
public void
- Add_Segment(SortWriter *self, SegReader *reader,
- I32Array *doc_map = NULL);
+ Add_Segment(SortWriter *self, SegReader *reader,
+ I32Array *doc_map = NULL);
public incremented Hash*
Metadata(SortWriter *self);
Modified: incubator/lucy/trunk/core/Lucy/Index/TermInfo.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/TermInfo.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/TermInfo.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/TermInfo.c Sun May 1 23:50:24 2011
@@ -21,15 +21,13 @@
#include "Lucy/Util/StringHelper.h"
TermInfo*
-TInfo_new(int32_t doc_freq)
-{
+TInfo_new(int32_t doc_freq) {
TermInfo *self = (TermInfo*)VTable_Make_Obj(TERMINFO);
return TInfo_init(self, doc_freq);
}
TermInfo*
-TInfo_init(TermInfo *self, int32_t doc_freq)
-{
+TInfo_init(TermInfo *self, int32_t doc_freq) {
self->doc_freq = doc_freq;
self->post_filepos = 0;
self->skip_filepos = 0;
@@ -38,8 +36,7 @@ TInfo_init(TermInfo *self, int32_t doc_f
}
TermInfo*
-TInfo_clone(TermInfo *self)
-{
+TInfo_clone(TermInfo *self) {
TermInfo *twin = TInfo_new(self->doc_freq);
twin->post_filepos = self->post_filepos;
twin->skip_filepos = self->skip_filepos;
@@ -48,55 +45,70 @@ TInfo_clone(TermInfo *self)
}
int32_t
-TInfo_get_doc_freq(TermInfo *self) { return self->doc_freq; }
+TInfo_get_doc_freq(TermInfo *self) {
+ return self->doc_freq;
+}
+
int64_t
-TInfo_get_lex_filepos(TermInfo *self) { return self->lex_filepos; }
+TInfo_get_lex_filepos(TermInfo *self) {
+ return self->lex_filepos;
+}
+
int64_t
-TInfo_get_post_filepos(TermInfo *self) { return self->post_filepos; }
+TInfo_get_post_filepos(TermInfo *self) {
+ return self->post_filepos;
+}
+
int64_t
-TInfo_get_skip_filepos(TermInfo *self) { return self->skip_filepos; }
+TInfo_get_skip_filepos(TermInfo *self) {
+ return self->skip_filepos;
+}
void
-TInfo_set_doc_freq(TermInfo *self, int32_t doc_freq)
- { self->doc_freq = doc_freq; }
+TInfo_set_doc_freq(TermInfo *self, int32_t doc_freq) {
+ self->doc_freq = doc_freq;
+}
+
void
-TInfo_set_lex_filepos(TermInfo *self, int64_t filepos)
- { self->lex_filepos = filepos; }
+TInfo_set_lex_filepos(TermInfo *self, int64_t filepos) {
+ self->lex_filepos = filepos;
+}
+
void
-TInfo_set_post_filepos(TermInfo *self, int64_t filepos)
- { self->post_filepos = filepos; }
+TInfo_set_post_filepos(TermInfo *self, int64_t filepos) {
+ self->post_filepos = filepos;
+}
+
void
-TInfo_set_skip_filepos(TermInfo *self, int64_t filepos)
- { self->skip_filepos = filepos; }
+TInfo_set_skip_filepos(TermInfo *self, int64_t filepos) {
+ self->skip_filepos = filepos;
+}
// TODO: this should probably be some sort of Dump variant rather than
// To_String.
CharBuf*
-TInfo_to_string(TermInfo *self)
-{
+TInfo_to_string(TermInfo *self) {
return CB_newf(
- "doc freq: %i32\n"
- "post filepos: %i64\n"
- "skip filepos: %i64\n"
- "index filepos: %i64",
- self->doc_freq, self->post_filepos,
- self->skip_filepos, self->lex_filepos
- );
+ "doc freq: %i32\n"
+ "post filepos: %i64\n"
+ "skip filepos: %i64\n"
+ "index filepos: %i64",
+ self->doc_freq, self->post_filepos,
+ self->skip_filepos, self->lex_filepos
+ );
}
void
-TInfo_mimic(TermInfo *self, Obj *other)
-{
+TInfo_mimic(TermInfo *self, Obj *other) {
TermInfo *twin = (TermInfo*)CERTIFY(other, TERMINFO);
- self->doc_freq = twin->doc_freq;
- self->post_filepos = twin->post_filepos;
- self->skip_filepos = twin->skip_filepos;
- self->lex_filepos = twin->lex_filepos;
+ self->doc_freq = twin->doc_freq;
+ self->post_filepos = twin->post_filepos;
+ self->skip_filepos = twin->skip_filepos;
+ self->lex_filepos = twin->lex_filepos;
}
void
-TInfo_reset(TermInfo *self)
-{
+TInfo_reset(TermInfo *self) {
self->doc_freq = 0;
self->post_filepos = 0;
self->skip_filepos = 0;
Modified: incubator/lucy/trunk/core/Lucy/Index/TermInfo.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/TermInfo.cfh?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/TermInfo.cfh (original)
+++ incubator/lucy/trunk/core/Lucy/Index/TermInfo.cfh Sun May 1 23:50:24 2011
@@ -37,7 +37,7 @@ class Lucy::Index::TermInfo cnick TInfo
inert incremented TermInfo*
new(int32_t doc_freq = 0);
- inert TermInfo*
+ inert TermInfo*
init(TermInfo *self, int32_t doc_freq = 0);
public int32_t
Modified: incubator/lucy/trunk/core/Lucy/Index/TermStepper.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Index/TermStepper.c?rev=1098445&r1=1098444&r2=1098445&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Index/TermStepper.c (original)
+++ incubator/lucy/trunk/core/Lucy/Index/TermStepper.c Sun May 1 23:50:24 2011
@@ -24,36 +24,31 @@
#include "Lucy/Util/StringHelper.h"
TermStepper*
-TermStepper_init(TermStepper *self)
-{
+TermStepper_init(TermStepper *self) {
Stepper_init((Stepper*)self);
self->value = NULL;
return self;
}
void
-TermStepper_destroy(TermStepper *self)
-{
+TermStepper_destroy(TermStepper *self) {
DECREF(self->value);
SUPER_DESTROY(self, TERMSTEPPER);
}
void
-TermStepper_reset(TermStepper *self)
-{
+TermStepper_reset(TermStepper *self) {
DECREF(self->value);
self->value = NULL;
}
Obj*
-TermStepper_get_value(TermStepper *self)
-{
+TermStepper_get_value(TermStepper *self) {
return self->value;
}
void
-TermStepper_set_value(TermStepper *self, Obj *value)
-{
+TermStepper_set_value(TermStepper *self, Obj *value) {
DECREF(self->value);
self->value = value ? INCREF(value) : NULL;
}