static VALUE frt_pq_alloc(VALUE klass) { PriQ *pq = ALLOC_AND_ZERO(PriQ); pq->capa = PQ_START_CAPA; pq->mem_capa = PQ_START_CAPA; pq->heap = ALLOC_N(VALUE, PQ_START_CAPA); pq->proc = Qnil; return Data_Wrap_Struct(klass, &frt_pq_mark, &frt_pq_free, pq); }
Index *index_new(Store *store, Analyzer *analyzer, HashSet *def_fields, bool create) { Index *self = ALLOC_AND_ZERO(Index); HashSetEntry *hse; /* FIXME: need to add these to the query parser */ self->config = default_config; mutex_init(&self->mutex, NULL); self->has_writes = false; if (store) { REF(store); self->store = store; } else { self->store = open_ram_store(); create = true; } if (analyzer) { self->analyzer = analyzer; REF(analyzer); } else { self->analyzer = mb_standard_analyzer_new(true); } if (create) { FieldInfos *fis = fis_new(STORE_YES, INDEX_YES, TERM_VECTOR_WITH_POSITIONS_OFFSETS); index_create(self->store, fis); fis_deref(fis); } /* options */ self->key = NULL; self->id_field = intern("id"); self->def_field = intern("id"); self->auto_flush = false; self->check_latest = true; REF(self->analyzer); self->qp = qp_new(self->analyzer); for (hse = def_fields->first; hse; hse = hse->next) { qp_add_field(self->qp, (Symbol)hse->elem, true, true); } /* Index is a convenience class so set qp convenience options */ self->qp->allow_any_fields = true; self->qp->clean_str = true; self->qp->handle_parse_errors = true; return self; }
Store *open_cmpd_store(Store *store, const char *name) { int count, i; off_t offset; char *fname; FileEntry *entry = NULL; Store *new_store = NULL; CompoundStore *volatile cmpd = NULL; InStream *volatile is = NULL; TRY cmpd = ALLOC_AND_ZERO(CompoundStore); cmpd->store = store; cmpd->name = name; cmpd->entries = h_new_str(&free, &free); is = cmpd->stream = store->open_input(store, cmpd->name); /* read the directory and init files */ count = is_read_vint(is); entry = NULL; for (i = 0; i < count; i++) { offset = (off_t)is_read_i64(is); fname = is_read_string(is); if (entry != NULL) { /* set length of the previous entry */ entry->length = offset - entry->offset; } entry = ALLOC(FileEntry); entry->offset = offset; h_set(cmpd->entries, fname, entry); } XCATCHALL if (is) is_close(is); if (cmpd->entries) h_destroy(cmpd->entries); free(cmpd); XENDTRY /* set the length of the final entry */ if (entry != NULL) { entry->length = is_length(is) - entry->offset; } new_store = store_new(); new_store->dir.cmpd = cmpd; new_store->touch = &cmpd_touch; new_store->exists = &cmpd_exists; new_store->remove = &cmpd_remove; new_store->rename = &cmpd_rename; new_store->count = &cmpd_count; new_store->clear = &cmpd_clear; new_store->length = &cmpd_length; new_store->each = &cmpd_each; new_store->close_i = &cmpd_close_i; new_store->new_output = &cmpd_new_output; new_store->open_input = &cmpd_open_input; new_store->open_lock_i = &cmpd_open_lock_i; new_store->close_lock_i = &cmpd_close_lock_i; return new_store; }