Ejemplo n.º 1
0
void TermBucket::clear(){

    if (!root) return;

    Term* curr = root;
    Term* old;
    while(curr->get_next()){
        old = curr;
        curr = curr->get_next();
        delete old;
    }
}
Ejemplo n.º 2
0
void TermBucket::write_term_bucket(ofstream &persistence)
{
    if (!root) return;

    // Iterate through the linked list and print each term.
    Term* curr = root;
    curr->write_term(persistence);
    while (curr->get_next())
    {
        curr = curr->get_next();
        curr->write_term(persistence);
    }
}
Ejemplo n.º 3
0
Term* TermBucket::find(string term)
{
    if (!root) return NULL;

    Term* curr = root;
    if (curr->get_name().compare(term) == 0) return curr;
    while (curr->get_next())
    {
        curr = curr->get_next();
        if (curr->get_name().compare(term) == 0) return curr;
    }
    return NULL;
}
Ejemplo n.º 4
0
void TermBucket::add_term_to_bucket(Term* term)
{

    // If there are no terms in the bucket, set root to newTerm.
    if (!root)
    {
        root = term;
        return;
    }

    // Otherwise, insert newTerm at the end of the linked list.
    Term* curr = root;
    while (curr->get_next()) curr = curr->get_next();
    curr->set_next(term);
}
Ejemplo n.º 5
0
bool TermBucket::has_word(string term)
{
    if (!root) return false;

    // Iterate through the linked list at this bucket,
    // checking each word for a match.
    Term* curr = root;
    if (curr->get_name().compare(term) == 0) return true;
    while (curr->get_next())
    {
        curr = curr->get_next();
        if (curr->get_name().compare(term) == 0) return true;
    }

    // By this point, it's checked every term (with no matches),
    // so return false.
    return false;
}