本文整理汇总了C++中Vec_Fetch函数的典型用法代码示例。如果您正苦于以下问题:C++ Vec_Fetch函数的具体用法?C++ Vec_Fetch怎么用?C++ Vec_Fetch使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vec_Fetch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HeatMap_Generate_Proximity_Boosts_IMP
Vector*
HeatMap_Generate_Proximity_Boosts_IMP(HeatMap *self, Vector *spans) {
Vector *boosts = Vec_new(0);
const size_t num_spans = Vec_Get_Size(spans);
if (num_spans > 1) {
for (size_t i = 0, max = num_spans - 1; i < max; i++) {
Span *span1 = (Span*)Vec_Fetch(spans, i);
for (size_t j = i + 1; j <= max; j++) {
Span *span2 = (Span*)Vec_Fetch(spans, j);
float prox_score
= HeatMap_Calc_Proximity_Boost(self, span1, span2);
if (prox_score == 0) {
break;
}
else {
int32_t length = Span_Get_Offset(span2)
- Span_Get_Offset(span1)
+ Span_Get_Length(span2);
Vec_Push(boosts,
(Obj*)Span_new(Span_Get_Offset(span1), length,
prox_score));
}
}
}
}
return boosts;
}
示例2: DefDelWriter_Delete_By_Term_IMP
void
DefDelWriter_Delete_By_Term_IMP(DefaultDeletionsWriter *self,
String *field, Obj *term) {
DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self);
for (size_t i = 0, max = Vec_Get_Size(ivars->seg_readers); i < max; i++) {
SegReader *seg_reader = (SegReader*)Vec_Fetch(ivars->seg_readers, i);
PostingListReader *plist_reader
= (PostingListReader*)SegReader_Fetch(
seg_reader, Class_Get_Name(POSTINGLISTREADER));
BitVector *bit_vec = (BitVector*)Vec_Fetch(ivars->bit_vecs, i);
PostingList *plist = plist_reader
? PListReader_Posting_List(plist_reader, field, term)
: NULL;
int32_t doc_id;
int32_t num_zapped = 0;
// Iterate through postings, marking each doc as deleted.
if (plist) {
while (0 != (doc_id = PList_Next(plist))) {
num_zapped += !BitVec_Get(bit_vec, (size_t)doc_id);
BitVec_Set(bit_vec, (size_t)doc_id);
}
if (num_zapped) { ivars->updated[i] = true; }
DECREF(plist);
}
}
}
示例3: DefDelWriter_Delete_By_Query_IMP
void
DefDelWriter_Delete_By_Query_IMP(DefaultDeletionsWriter *self, Query *query) {
DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self);
Compiler *compiler = Query_Make_Compiler(query, (Searcher*)ivars->searcher,
Query_Get_Boost(query), false);
for (size_t i = 0, max = Vec_Get_Size(ivars->seg_readers); i < max; i++) {
SegReader *seg_reader = (SegReader*)Vec_Fetch(ivars->seg_readers, i);
BitVector *bit_vec = (BitVector*)Vec_Fetch(ivars->bit_vecs, i);
Matcher *matcher = Compiler_Make_Matcher(compiler, seg_reader, false);
if (matcher) {
int32_t doc_id;
int32_t num_zapped = 0;
// Iterate through matches, marking each doc as deleted.
while (0 != (doc_id = Matcher_Next(matcher))) {
num_zapped += !BitVec_Get(bit_vec, (size_t)doc_id);
BitVec_Set(bit_vec, (size_t)doc_id);
}
if (num_zapped) { ivars->updated[i] = true; }
DECREF(matcher);
}
}
DECREF(compiler);
}
示例4: DefDelWriter_Metadata_IMP
Hash*
DefDelWriter_Metadata_IMP(DefaultDeletionsWriter *self) {
DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self);
DefDelWriter_Metadata_t super_meta
= (DefDelWriter_Metadata_t)SUPER_METHOD_PTR(DEFAULTDELETIONSWRITER,
LUCY_DefDelWriter_Metadata);
Hash *const metadata = super_meta(self);
Hash *const files = Hash_new(0);
for (size_t i = 0, max = Vec_Get_Size(ivars->seg_readers); i < max; i++) {
SegReader *seg_reader = (SegReader*)Vec_Fetch(ivars->seg_readers, i);
if (ivars->updated[i]) {
BitVector *deldocs = (BitVector*)Vec_Fetch(ivars->bit_vecs, i);
Segment *segment = SegReader_Get_Segment(seg_reader);
Hash *mini_meta = Hash_new(2);
Hash_Store_Utf8(mini_meta, "count", 5,
(Obj*)Str_newf("%u32", (uint32_t)BitVec_Count(deldocs)));
Hash_Store_Utf8(mini_meta, "filename", 8,
(Obj*)S_del_filename(self, seg_reader));
Hash_Store(files, Seg_Get_Name(segment), (Obj*)mini_meta);
}
}
Hash_Store_Utf8(metadata, "files", 5, (Obj*)files);
return metadata;
}
示例5: DefDelWriter_Seg_Deletions_IMP
Matcher*
DefDelWriter_Seg_Deletions_IMP(DefaultDeletionsWriter *self,
SegReader *seg_reader) {
DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self);
Matcher *deletions = NULL;
Segment *segment = SegReader_Get_Segment(seg_reader);
String *seg_name = Seg_Get_Name(segment);
Integer *tick_obj = (Integer*)Hash_Fetch(ivars->name_to_tick,
seg_name);
size_t tick = tick_obj ? (size_t)Int_Get_Value(tick_obj) : 0;
SegReader *candidate = tick_obj
? (SegReader*)Vec_Fetch(ivars->seg_readers, tick)
: NULL;
if (tick_obj) {
DeletionsReader *del_reader
= (DeletionsReader*)SegReader_Obtain(
candidate, Class_Get_Name(DELETIONSREADER));
if (ivars->updated[tick] || DelReader_Del_Count(del_reader)) {
BitVector *deldocs = (BitVector*)Vec_Fetch(ivars->bit_vecs, tick);
deletions = (Matcher*)BitVecMatcher_new(deldocs);
}
}
else { // Sanity check.
THROW(ERR, "Couldn't find SegReader %o", seg_reader);
}
return deletions;
}
示例6: DefDelWriter_Finish_IMP
void
DefDelWriter_Finish_IMP(DefaultDeletionsWriter *self) {
DefaultDeletionsWriterIVARS *const ivars = DefDelWriter_IVARS(self);
Folder *const folder = ivars->folder;
for (size_t i = 0, max = Vec_Get_Size(ivars->seg_readers); i < max; i++) {
SegReader *seg_reader = (SegReader*)Vec_Fetch(ivars->seg_readers, i);
if (ivars->updated[i]) {
BitVector *deldocs = (BitVector*)Vec_Fetch(ivars->bit_vecs, i);
int32_t doc_max = SegReader_Doc_Max(seg_reader);
size_t byte_size = (((size_t)doc_max + 1) + 7) / 8;
size_t new_max = byte_size * 8 - 1;
String *filename = S_del_filename(self, seg_reader);
OutStream *outstream = Folder_Open_Out(folder, filename);
if (!outstream) { RETHROW(INCREF(Err_get_error())); }
// Ensure that we have 1 bit for each doc in segment.
BitVec_Grow(deldocs, new_max);
// Write deletions data and clean up.
OutStream_Write_Bytes(outstream,
(char*)BitVec_Get_Raw_Bits(deldocs),
byte_size);
OutStream_Close(outstream);
DECREF(outstream);
DECREF(filename);
}
}
Seg_Store_Metadata_Utf8(ivars->segment, "deletions", 9,
(Obj*)DefDelWriter_Metadata(self));
}
示例7: PolyAnalyzer_Transform_Text_IMP
Inversion*
PolyAnalyzer_Transform_Text_IMP(PolyAnalyzer *self, String *text) {
Vector *const analyzers = PolyAnalyzer_IVARS(self)->analyzers;
const uint32_t num_analyzers = Vec_Get_Size(analyzers);
Inversion *retval;
if (num_analyzers == 0) {
size_t token_len = Str_Get_Size(text);
const char *buf = Str_Get_Ptr8(text);
Token *seed = Token_new(buf, token_len, 0, token_len, 1.0f, 1);
retval = Inversion_new(seed);
DECREF(seed);
}
else {
Analyzer *first_analyzer = (Analyzer*)Vec_Fetch(analyzers, 0);
retval = Analyzer_Transform_Text(first_analyzer, text);
for (uint32_t i = 1; i < num_analyzers; i++) {
Analyzer *analyzer = (Analyzer*)Vec_Fetch(analyzers, i);
Inversion *new_inversion = Analyzer_Transform(analyzer, retval);
DECREF(retval);
retval = new_inversion;
}
}
return retval;
}
示例8: S_compose_inner_queries
static void
S_compose_inner_queries(QueryParser *self, Vector *elems,
String *default_field) {
const int32_t default_occur = QParser_IVARS(self)->default_occur;
// Generate all queries. Apply any fields.
for (uint32_t i = Vec_Get_Size(elems); i--;) {
String *field = default_field;
ParserElem *elem = (ParserElem*)Vec_Fetch(elems, i);
// Apply field.
if (i > 0) {
// Field specifier must immediately precede any query.
ParserElem* maybe_field_elem
= (ParserElem*)Vec_Fetch(elems, i - 1);
if (ParserElem_Get_Type(maybe_field_elem) == TOKEN_FIELD) {
field = (String*)ParserElem_As(maybe_field_elem, STRING);
}
}
if (ParserElem_Get_Type(elem) == TOKEN_STRING) {
String *text = (String*)ParserElem_As(elem, STRING);
LeafQuery *query = LeafQuery_new(field, text);
ParserElem *new_elem
= ParserElem_new(TOKEN_QUERY, (Obj*)query);
if (default_occur == MUST) {
ParserElem_Require(new_elem);
}
Vec_Store(elems, i, (Obj*)new_elem);
}
}
}
示例9: Indexer_Add_Index_IMP
void
Indexer_Add_Index_IMP(Indexer *self, Obj *index) {
IndexerIVARS *const ivars = Indexer_IVARS(self);
Folder *other_folder = NULL;
IndexReader *reader = NULL;
if (Obj_is_a(index, FOLDER)) {
other_folder = (Folder*)INCREF(index);
}
else if (Obj_is_a(index, STRING)) {
other_folder = (Folder*)FSFolder_new((String*)index);
}
else {
THROW(ERR, "Invalid type for 'index': %o", Obj_get_class_name(index));
}
reader = IxReader_open((Obj*)other_folder, NULL, NULL);
if (reader == NULL) {
THROW(ERR, "Index doesn't seem to contain any data");
}
else {
Schema *schema = ivars->schema;
Schema *other_schema = IxReader_Get_Schema(reader);
Vector *other_fields = Schema_All_Fields(other_schema);
Vector *seg_readers = IxReader_Seg_Readers(reader);
// Validate schema compatibility and add fields.
Schema_Eat(schema, other_schema);
// Add fields to Segment.
for (size_t i = 0, max = Vec_Get_Size(other_fields); i < max; i++) {
String *other_field = (String*)Vec_Fetch(other_fields, i);
Seg_Add_Field(ivars->segment, other_field);
}
DECREF(other_fields);
// Add all segments.
for (size_t i = 0, max = Vec_Get_Size(seg_readers); i < max; i++) {
SegReader *seg_reader = (SegReader*)Vec_Fetch(seg_readers, i);
DeletionsReader *del_reader
= (DeletionsReader*)SegReader_Fetch(
seg_reader, Class_Get_Name(DELETIONSREADER));
Matcher *deletions = del_reader
? DelReader_Iterator(del_reader)
: NULL;
I32Array *doc_map = DelWriter_Generate_Doc_Map(
ivars->del_writer, deletions,
SegReader_Doc_Max(seg_reader),
(int32_t)Seg_Get_Count(ivars->segment));
SegWriter_Add_Segment(ivars->seg_writer, seg_reader, doc_map);
DECREF(deletions);
DECREF(doc_map);
}
DECREF(seg_readers);
}
DECREF(reader);
DECREF(other_folder);
}
示例10: HeatMap_Flatten_Spans_IMP
Vector*
HeatMap_Flatten_Spans_IMP(HeatMap *self, Vector *spans) {
const size_t num_spans = Vec_Get_Size(spans);
UNUSED_VAR(self);
if (!num_spans) {
return Vec_new(0);
}
else {
Vector *flattened = S_flattened_but_empty_spans(spans);
const size_t num_raw_flattened = Vec_Get_Size(flattened);
// Iterate over each of the source spans, contributing their scores to
// any destination span that falls within range.
size_t dest_tick = 0;
for (size_t i = 0; i < num_spans; i++) {
Span *source_span = (Span*)Vec_Fetch(spans, i);
int32_t source_span_offset = Span_Get_Offset(source_span);
int32_t source_span_len = Span_Get_Length(source_span);
int32_t source_span_end = source_span_offset + source_span_len;
// Get the location of the flattened span that shares the source
// span's offset.
for (; dest_tick < num_raw_flattened; dest_tick++) {
Span *dest_span = (Span*)Vec_Fetch(flattened, dest_tick);
if (Span_Get_Offset(dest_span) == source_span_offset) {
break;
}
}
// Fill in scores.
for (size_t j = dest_tick; j < num_raw_flattened; j++) {
Span *dest_span = (Span*)Vec_Fetch(flattened, j);
if (Span_Get_Offset(dest_span) == source_span_end) {
break;
}
else {
float new_weight = Span_Get_Weight(dest_span)
+ Span_Get_Weight(source_span);
Span_Set_Weight(dest_span, new_weight);
}
}
}
// Leave holes instead of spans that don't have any score.
dest_tick = 0;
for (size_t i = 0; i < num_raw_flattened; i++) {
Span *span = (Span*)Vec_Fetch(flattened, i);
if (Span_Get_Weight(span)) {
Vec_Store(flattened, dest_tick++, INCREF(span));
}
}
Vec_Excise(flattened, dest_tick, num_raw_flattened - dest_tick);
return flattened;
}
}
示例11: S_parse_subqueries
static void
S_parse_subqueries(QueryParser *self, Vector *elems) {
const int32_t default_occur = QParser_IVARS(self)->default_occur;
while (1) {
// Work from the inside out, starting with the leftmost innermost
// paren group.
size_t left = SIZE_MAX;
size_t right = SIZE_MAX;
String *field = NULL;
for (size_t i = 0, max = Vec_Get_Size(elems); i < max; i++) {
ParserElem *elem = (ParserElem*)Vec_Fetch(elems, i);
uint32_t type = ParserElem_Get_Type(elem);
if (type == TOKEN_OPEN_PAREN) {
left = i;
}
else if (type == TOKEN_CLOSE_PAREN) {
right = i;
break;
}
else if (type == TOKEN_FIELD && i < max - 1) {
// If a field applies to an enclosing paren, pass it along.
ParserElem *next_elem = (ParserElem*)Vec_Fetch(elems, i + 1);
uint32_t next_type = ParserElem_Get_Type(next_elem);
if (next_type == TOKEN_OPEN_PAREN) {
field = (String*)ParserElem_As(elem, STRING);
}
}
}
// Break out of loop when there are no parens left.
if (right == SIZE_MAX) {
break;
}
// Create the subquery.
Vector *sub_elems = Vec_Slice(elems, left + 1, right - left - 1);
Query *subquery = S_parse_subquery(self, sub_elems, field, true);
ParserElem *new_elem = ParserElem_new(TOKEN_QUERY, (Obj*)subquery);
if (default_occur == MUST) {
ParserElem_Require(new_elem);
}
DECREF(sub_elems);
// Replace the elements used to create the subquery with the subquery
// itself.
if (left > 0) {
ParserElem *maybe_field = (ParserElem*)Vec_Fetch(elems, left - 1);
uint32_t maybe_field_type = ParserElem_Get_Type(maybe_field);
if (maybe_field_type == TOKEN_FIELD) {
left -= 1;
}
}
Vec_Excise(elems, left + 1, right - left);
Vec_Store(elems, left, (Obj*)new_elem);
}
}
示例12: QParser_init
QueryParser*
QParser_init(QueryParser *self, Schema *schema, Analyzer *analyzer,
String *default_boolop, Vector *fields) {
QueryParserIVARS *const ivars = QParser_IVARS(self);
// Init.
ivars->heed_colons = false;
ivars->lexer = QueryLexer_new();
// Assign.
ivars->schema = (Schema*)INCREF(schema);
ivars->analyzer = (Analyzer*)INCREF(analyzer);
ivars->default_boolop = default_boolop
? Str_Clone(default_boolop)
: Str_new_from_trusted_utf8("OR", 2);
if (fields) {
ivars->fields = Vec_Clone(fields);
for (uint32_t i = 0, max = Vec_Get_Size(fields); i < max; i++) {
CERTIFY(Vec_Fetch(fields, i), STRING);
}
Vec_Sort(ivars->fields);
}
else {
Vector *all_fields = Schema_All_Fields(schema);
uint32_t num_fields = Vec_Get_Size(all_fields);
ivars->fields = Vec_new(num_fields);
for (uint32_t i = 0; i < num_fields; i++) {
String *field = (String*)Vec_Fetch(all_fields, i);
FieldType *type = Schema_Fetch_Type(schema, field);
if (type && FType_Indexed(type)) {
Vec_Push(ivars->fields, INCREF(field));
}
}
DECREF(all_fields);
}
Vec_Sort(ivars->fields);
// Derive default "occur" from default boolean operator.
if (Str_Equals_Utf8(ivars->default_boolop, "OR", 2)) {
ivars->default_occur = SHOULD;
}
else if (Str_Equals_Utf8(ivars->default_boolop, "AND", 3)) {
ivars->default_occur = MUST;
}
else {
THROW(ERR, "Invalid value for default_boolop: %o", ivars->default_boolop);
}
return self;
}
示例13: S_ormatcher_init2
static ORMatcher*
S_ormatcher_init2(ORMatcher *self, ORMatcherIVARS *ivars, Vector *children,
Similarity *sim) {
// Init.
PolyMatcher_init((PolyMatcher*)self, children, sim);
ivars->size = 0;
// Derive.
ivars->max_size = (uint32_t)Vec_Get_Size(children);
// Allocate.
ivars->heap = (HeapedMatcherDoc**)CALLOCATE(ivars->max_size + 1, sizeof(HeapedMatcherDoc*));
// Create a pool of HMDs. Encourage CPU cache hits by using a single
// allocation for all of them.
size_t amount_to_malloc = (ivars->max_size + 1) * sizeof(HeapedMatcherDoc);
ivars->blob = (char*)MALLOCATE(amount_to_malloc);
ivars->pool = (HeapedMatcherDoc**)CALLOCATE(ivars->max_size + 1, sizeof(HeapedMatcherDoc*));
for (uint32_t i = 1; i <= ivars->max_size; i++) {
size_t offset = i * sizeof(HeapedMatcherDoc);
HeapedMatcherDoc *hmd = (HeapedMatcherDoc*)(ivars->blob + offset);
ivars->pool[i] = hmd;
}
// Prime queue.
for (uint32_t i = 0; i < ivars->max_size; i++) {
Matcher *matcher = (Matcher*)Vec_Fetch(children, i);
if (matcher) {
S_add_element(self, ivars, (Matcher*)INCREF(matcher), 0);
}
}
return self;
}
示例14: PolySearcher_init
PolySearcher*
PolySearcher_init(PolySearcher *self, Schema *schema, Vector *searchers) {
const uint32_t num_searchers = Vec_Get_Size(searchers);
int32_t *starts_array = (int32_t*)MALLOCATE(num_searchers * sizeof(int32_t));
int32_t doc_max = 0;
Searcher_init((Searcher*)self, schema);
PolySearcherIVARS *const ivars = PolySearcher_IVARS(self);
ivars->searchers = (Vector*)INCREF(searchers);
ivars->starts = NULL; // Safe cleanup.
for (uint32_t i = 0; i < num_searchers; i++) {
Searcher *searcher
= (Searcher*)CERTIFY(Vec_Fetch(searchers, i), SEARCHER);
Schema *candidate = Searcher_Get_Schema(searcher);
Class *orig_class = Schema_Get_Class(schema);
Class *candidate_class = Schema_Get_Class(candidate);
// Confirm that searchers all use the same schema.
if (orig_class != candidate_class) {
THROW(ERR, "Conflicting schemas: '%o', '%o'",
Schema_Get_Class_Name(schema),
Schema_Get_Class_Name(candidate));
}
// Derive doc_max and relative start offsets.
starts_array[i] = (int32_t)doc_max;
doc_max += Searcher_Doc_Max(searcher);
}
ivars->doc_max = doc_max;
ivars->starts = I32Arr_new_steal(starts_array, num_searchers);
return self;
}
示例15: SortEx_Shrink_IMP
void
SortEx_Shrink_IMP(SortExternal *self) {
SortExternalIVARS *const ivars = SortEx_IVARS(self);
if (ivars->buf_max - ivars->buf_tick > 0) {
size_t buf_count = SortEx_Buffer_Count(self);
size_t size = buf_count * sizeof(Obj*);
if (ivars->buf_tick > 0) {
Obj **start = ivars->buffer + ivars->buf_tick;
memmove(ivars->buffer, start, size);
}
ivars->buffer = (Obj**)REALLOCATE(ivars->buffer, size);
ivars->buf_tick = 0;
ivars->buf_max = buf_count;
ivars->buf_cap = buf_count;
}
else {
FREEMEM(ivars->buffer);
ivars->buffer = NULL;
ivars->buf_tick = 0;
ivars->buf_max = 0;
ivars->buf_cap = 0;
}
ivars->scratch_cap = 0;
FREEMEM(ivars->scratch);
ivars->scratch = NULL;
for (uint32_t i = 0, max = Vec_Get_Size(ivars->runs); i < max; i++) {
SortExternal *run = (SortExternal*)Vec_Fetch(ivars->runs, i);
SortEx_Shrink(run);
}
}