Beispiel #1
0
tree_struct *find_word(index_struct *idx, char *word)
{
  word_len = strlen(word);
  int i;

  for(i = 0; i < word_len; i++)
    stemmed_word[i] = idx->f(word[i]);
  stemmed_word[word_len] = 0;
  
  return find_in_tree(idx, stemmed_word,  idx->tree);
}
Beispiel #2
0
int main(void) {
  btree<std::string> bts;

  bts.insert("comp3000");
  bts.insert("comp3171");
  bts.insert("comp2000");
  bts.insert("comp1000");

  find_in_tree(bts, std::string("comp3171"));

  btree<int> bti;

  bti.insert(1);
  bti.insert(10);
  bti.insert(3);
  bti.insert(4);

  find_in_tree(bti, 100);

  return 0;
}
Beispiel #3
0
static tree_struct*
find_in_tree(index_struct *idx, char *suffix, tree_struct *tree)
{
  if(tree == NULL) return NULL;
  
  if(suffix[0] == 0) return tree;
  
  if(tree->tree_type == WORD_TREE){
    
    tree_struct * new_tree = tree->tree_subtrees[ (int) suffix[0]];
    return find_in_tree(idx, suffix+1, new_tree);
  
  } else {
    array_struct * array = (array_struct*) tree;
    
    int nprefixes = array->array_nprefixes;
    int nsuffixes = array->array_nsuffixes;
    int suffix_len = strlen(suffix);
    int i;
    hits_struct *all_hits;    

    nhits = 0;
    
    for(i=0; i<nprefixes; i++){
      char *word = array->array_suffixes[i].suffix_word;
      if(!strncmp(suffix, word, suffix_len)){
        add_hit(array->array_suffixes[i].suffix_num);
      }
    }
    for(i=0; i<nsuffixes; i++){
      char *word = array->array_suffixes[MAX_LINEAR_SEARCH+i].suffix_word;
      if(!strncmp(suffix, word, suffix_len)){
        add_hit(array->array_suffixes[MAX_LINEAR_SEARCH+i].suffix_num);
      }
    }
    if(nhits == 0) return NULL;
    all_hits = index_alloc(sizeof(hits_struct) + sizeof(int) * nhits);
    all_hits->hits_type = WORD_HITS;
    all_hits->hits_nbr = nhits;
    memcpy(all_hits->hits_words, hits, nhits * sizeof(int));
    return (tree_struct*) all_hits;
  }
}