本文整理汇总了C++中Vec_Get_Size函数的典型用法代码示例。如果您正苦于以下问题:C++ Vec_Get_Size函数的具体用法?C++ Vec_Get_Size怎么用?C++ Vec_Get_Size使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vec_Get_Size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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;
}
}
示例3: S_dump_array
static Obj*
S_dump_array(Vector *array) {
Vector *dump = Vec_new(Vec_Get_Size(array));
for (size_t i = 0, max = Vec_Get_Size(array); i < max; i++) {
Obj *elem = Vec_Fetch(array, i);
if (elem) {
Vec_Store(dump, i, Freezer_dump(elem));
}
}
return (Obj*)dump;
}
示例4: S_load_from_array
Obj*
S_load_from_array(Vector *dump) {
Vector *loaded = Vec_new(Vec_Get_Size(dump));
for (size_t i = 0, max = Vec_Get_Size(dump); i < max; i++) {
Obj *elem_dump = Vec_Fetch(dump, i);
if (elem_dump) {
Vec_Store(loaded, i, Freezer_load(elem_dump));
}
}
return (Obj*)loaded;
}
示例5: 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;
}
示例6: PhraseQuery_Make_Compiler_IMP
Compiler*
PhraseQuery_Make_Compiler_IMP(PhraseQuery *self, Searcher *searcher,
float boost, bool subordinate) {
PhraseQueryIVARS *const ivars = PhraseQuery_IVARS(self);
if (Vec_Get_Size(ivars->terms) == 1) {
// Optimize for one-term "phrases".
Obj *term = Vec_Fetch(ivars->terms, 0);
TermQuery *term_query = TermQuery_new(ivars->field, term);
TermCompiler *term_compiler;
TermQuery_Set_Boost(term_query, ivars->boost);
term_compiler
= (TermCompiler*)TermQuery_Make_Compiler(term_query, searcher,
boost, subordinate);
DECREF(term_query);
return (Compiler*)term_compiler;
}
else {
PhraseCompiler *compiler
= PhraseCompiler_new(self, searcher, boost);
if (!subordinate) {
PhraseCompiler_Normalize(compiler);
}
return (Compiler*)compiler;
}
}
示例7: PolyLex_Reset_IMP
void
PolyLex_Reset_IMP(PolyLexicon *self) {
PolyLexiconIVARS *const ivars = PolyLex_IVARS(self);
Vector *seg_lexicons = ivars->seg_lexicons;
uint32_t num_segs = Vec_Get_Size(seg_lexicons);
SegLexQueue *lex_q = ivars->lex_q;
// Empty out the queue.
while (1) {
SegLexicon *seg_lex = (SegLexicon*)SegLexQ_Pop(lex_q);
if (seg_lex == NULL) { break; }
DECREF(seg_lex);
}
// Fill the queue with valid SegLexicons.
for (uint32_t i = 0; i < num_segs; i++) {
SegLexicon *const seg_lexicon
= (SegLexicon*)Vec_Fetch(seg_lexicons, i);
SegLex_Reset(seg_lexicon);
if (SegLex_Next(seg_lexicon)) {
SegLexQ_Insert(ivars->lex_q, INCREF(seg_lexicon));
}
}
if (ivars->term != NULL) {
DECREF(ivars->term);
ivars->term = NULL;
}
}
示例8: PolyLex_init
PolyLexicon*
PolyLex_init(PolyLexicon *self, String *field, Vector *sub_readers) {
uint32_t num_sub_readers = Vec_Get_Size(sub_readers);
Vector *seg_lexicons = Vec_new(num_sub_readers);
// Init.
Lex_init((Lexicon*)self, field);
PolyLexiconIVARS *const ivars = PolyLex_IVARS(self);
ivars->term = NULL;
ivars->lex_q = SegLexQ_new(num_sub_readers);
// Derive.
for (uint32_t i = 0; i < num_sub_readers; i++) {
LexiconReader *lex_reader = (LexiconReader*)Vec_Fetch(sub_readers, i);
if (lex_reader && CERTIFY(lex_reader, LEXICONREADER)) {
Lexicon *seg_lexicon = LexReader_Lexicon(lex_reader, field, NULL);
if (seg_lexicon != NULL) {
Vec_Push(seg_lexicons, (Obj*)seg_lexicon);
}
}
}
ivars->seg_lexicons = seg_lexicons;
PolyLex_Reset(self);
return self;
}
示例9: 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;
}
示例10: S_flattened_but_empty_spans
// Create all the spans needed by HeatMap_Flatten_Spans, based on the source
// offsets and lengths... but leave the scores at 0.
static Vector*
S_flattened_but_empty_spans(Vector *spans) {
const size_t num_spans = Vec_Get_Size(spans);
int32_t *bounds = (int32_t*)MALLOCATE((num_spans * 2) * sizeof(int32_t));
// Assemble a list of all unique start/end boundaries.
for (size_t i = 0; i < num_spans; i++) {
Span *span = (Span*)Vec_Fetch(spans, i);
bounds[i] = Span_Get_Offset(span);
bounds[i + num_spans] = Span_Get_Offset(span) + Span_Get_Length(span);
}
qsort(bounds, num_spans * 2, sizeof(int32_t), S_compare_i32);
size_t num_bounds = 0;
int32_t last = INT32_MAX;
for (size_t i = 0; i < num_spans * 2; i++) {
if (bounds[i] != last) {
bounds[num_bounds++] = bounds[i];
last = bounds[i];
}
}
// Create one Span for each zone between two bounds.
Vector *flattened = Vec_new(num_bounds - 1);
for (size_t i = 0; i < num_bounds - 1; i++) {
int32_t start = bounds[i];
int32_t length = bounds[i + 1] - start;
Vec_Push(flattened, (Obj*)Span_new(start, length, 0.0f));
}
FREEMEM(bounds);
return flattened;
}
示例11: SortWriter_Add_Inverted_Doc_IMP
void
SortWriter_Add_Inverted_Doc_IMP(SortWriter *self, Inverter *inverter,
int32_t doc_id) {
SortWriterIVARS *const ivars = SortWriter_IVARS(self);
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
= S_lazy_init_field_writer(self, field_num);
SortFieldWriter_Add(field_writer, doc_id,
Inverter_Get_Value(inverter));
}
}
// If our SortFieldWriters have collectively passed the memory threshold,
// flush all of them, then reset the counter which tracks memory
// consumption.
if ((size_t)Counter_Get_Value(ivars->counter) > ivars->mem_thresh) {
for (size_t i = 0; i < Vec_Get_Size(ivars->field_writers); i++) {
SortFieldWriter *const field_writer
= (SortFieldWriter*)Vec_Fetch(ivars->field_writers, i);
if (field_writer) { SortFieldWriter_Flush(field_writer); }
}
Counter_Reset(ivars->counter);
ivars->flush_at_finish = true;
}
}
示例12: 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);
}
示例13: 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);
}
}
}
示例14: 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;
}
示例15: 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));
}