void HashTable<Object>::insert( const Object & x )
{
      // Insert x as active
    int currentPos = findPos( x );
    if( isActive( currentPos ) )
        throw DuplicateItemException( );
    array[ currentPos ] = HashEntry( x, ACTIVE );

    if( ++occupied > array.size( ) / 2 )
        rehash( );
}
Example #2
0
void TagReplacer::addTag(std::string tagText, std::string replaceText)
{
    // first make sure tag doesn't already exist
    auto it = m_replacementTextMap.find(tagText);

    // if the tag already existed, throw an exception
    if(it != m_replacementTextMap.end())
    {
        throw DuplicateItemException("Duplicate item: " + tagText);
    }

    m_replacementTextMap.insert(std::make_pair<std::string, std::string>(tagText, replaceText));
}
void SplayTree<Comparable>::insert( const Comparable & x )
{
    static BinaryNode<Comparable> *newNode = NULL;

    if( newNode == NULL )
        newNode = new BinaryNode<Comparable>;
    newNode->element = x;

    if( root == nullNode )
    {
        newNode->left = newNode->right = nullNode;
        root = newNode;
    }
    else
    {
        splay( x, root );
        if( x < root->element )
        {
            newNode->left = root->left;
            newNode->right = root;
            root->left = nullNode;
            root = newNode;
        }
        else
        if( root->element < x )
        {
            newNode->right = root->right;
            newNode->left = root;
            root->right = nullNode;
            root = newNode;
        }
        else
            throw DuplicateItemException( );
    }
    newNode = NULL;   // So next insert will call new
}