/*********************************************** !!!! DO NOT EDIT THIS FILE !!!! This file was auto-generated by Build.PL from lib/KinoSearch/Index/TermBuffer.pm See KinoSearch::Docs::DevGuide for details. ***********************************************/ #line 80 "lib/KinoSearch/Index/TermBuffer.pm" #include "KinoSearchIndexTermBuffer.h" static void Kino_TermBuf_set_text_len(TermBuffer*, I32); TermBuffer* Kino_TermBuf_new(I32 finfos_size) { TermBuffer *term_buf; /* allocate */ Kino_New(0, term_buf, 1, TermBuffer); /* reset the TermBuffer */ term_buf->termstring = NULL; Kino_TermBuf_reset(term_buf); /* derive max_field_num */ term_buf->max_field_num = finfos_size - 1; return term_buf; } /* Decode the next term in a term dictionary file (.tii, .tis), but don't turn * it into a full-fledged Term object. */ void Kino_TermBuf_read(TermBuffer *term_buf, InStream *instream) { I32 text_overlap, finish_chars_len, total_text_len, field_num; /* read bytes which are shared between the last term text and this */ text_overlap = instream->read_vint(instream); finish_chars_len = instream->read_vint(instream); total_text_len = text_overlap + finish_chars_len; Kino_TermBuf_set_text_len(term_buf, total_text_len); instream->read_chars(instream, term_buf->termstring->ptr, (text_overlap + KINO_FIELD_NUM_LEN), finish_chars_len); /* read field num */ field_num = instream->read_vint(instream); if (field_num > term_buf->max_field_num && field_num != -1) Kino_confess("Internal error: field_num %d > max_field_num %d", field_num, term_buf->max_field_num); Kino_encode_bigend_U16( (U16)field_num, term_buf->termstring->ptr); } /* Set the TermBuffer object to a sentinel state, indicating that it does not * hold a valid Term */ void Kino_TermBuf_reset(TermBuffer *term_buf) { if (term_buf->termstring != NULL) { Kino_BB_destroy(term_buf->termstring); term_buf->termstring = NULL; } term_buf->text_len = 0; } void Kino_TermBuf_set_termstring(TermBuffer *term_buf, char* ptr, I32 len) { /* the passed in len includes the length of the encoded field num */ if (len < 2) Kino_confess("can't set_termstring with a len < 2: %d", len); Kino_TermBuf_set_text_len(term_buf, len - KINO_FIELD_NUM_LEN); Kino_BB_assign_string(term_buf->termstring, ptr, len); } /* Set the length of the term text, and ensure that there's enough memory * allocated to hold term text that size. */ static void Kino_TermBuf_set_text_len(TermBuffer *term_buf, I32 new_len) { ByteBuf* termstring = term_buf->termstring; /* initialize if necessary, with a field number of 0 */ if (termstring == NULL) { termstring = Kino_BB_new_string("\0\0", 2); term_buf->termstring = termstring; } /* realloc and set lengths */ Kino_BB_grow(termstring, new_len + KINO_FIELD_NUM_LEN); termstring->size = new_len + KINO_FIELD_NUM_LEN; term_buf->text_len = new_len; /* null-terminate */ termstring->ptr[ termstring->size ] = '\0'; } void Kino_TermBuf_destroy(TermBuffer *term_buf) { Kino_TermBuf_reset(term_buf); Kino_Safefree(term_buf); }