Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c++ Simple Class Question

Name: Anonymous 2007-06-27 0:40 ID:CjAL5fOI

I have a class called htable, when it reaches a certain size it will rehash itself. Heres the pseudo code:

/* Creates new table, and deletes old one. */
Htable Htable::htable_rehash(){
   make new Htable;
   add old values to new table;
        delete old table;
   return new Htable;
}

to call it I would say hashtable = hashtable .htable_rehash();

My question is this: do i need to free the memory in the old hash table in the class, or will it be deleted when i say table = table.rehash?

Name: Anonymous 2007-06-30 15:18 ID:gDMKl3mZ

>>39

SHIT CODE YOU FAGGOT

(Map_step(position) % capacity, true) <- WHAT THE FUCK IS THIS YOU IDIOT


int Map::insert(std::string key, std::string value)

{

    // Rehash if we are too full

    if(percent_full() >= REHASH_PERCENT)

        rehash();



    unsigned int position = hash(key)%capacity;



    if(insert_key(key, position))

        return frequencies2[position];



    // There is another key at this position   

    for(unsigned int scanpos=Map_step(position) % capacity; scanpos!=(position); (Map_step(position) % capacity, true))

        if(insert_key(key, position))

            return frequencies2[position];



    return 0;

}



// Returns false if there is another key at that position.

bool Map::insert_key(std::string key, unsigned int position)

{

    if(frequencies[position]==0)

    {

        itemcount++;

        frequencies2[position]=1;

        keys2[position]=key;

        return true;

    }

   

    if(keys2[position]==key)

    {

        frequencies2[position]++;

        return true;

    }

    return false;

}


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List