Beispiel #1
0
void* StdMap_remove( StdMap* self, const IKey* key )
{
    void* ret = 0;

    IPIterator* it = self->entries->positions( self->entries );
    while ( it->hasNext( it ) )
    {
        const IPosition* p = it->next( it );
        const StdEntry* entry = (StdEntry*) p->getElement( p );
        const IKey* e_key = (const IKey*) StdEntry_getKey( entry );

        if ( e_key->contentEquals( e_key, key ) )
        {
            StdEntry* removed_entry = (StdEntry*) self->entries->remove( self->entries, p );
            IValue* v = (IValue*) StdEntry_replaceValue( removed_entry, NULL );
            ret = v->replaceValue( v, NULL );

            free_StdEntry( removed_entry );
            v->free( v );
            break;
        }
    }
    it->free( it );

    return ret;
}
Beispiel #2
0
void* StdMap_put_IValue( StdMap* self, const IKey* key, StdValue* aValue )
{
    void* ret = 0;

    int inserted = 0;

    IPIterator* it = self->entries->positions( self->entries );
    bool loop = TRUE;
    while ( loop && it->hasNext( it ) )
    {
        const IPosition* p = it->next( it );
        const IEntry* entry = p->getElement( p );
        const IKey* e_key = entry->getKey( entry );

        if ( e_key->contentEquals( e_key, key ) )
        {
            IValue* value = (IValue*) StdEntry_replaceValue( (StdEntry*) entry, aValue );
            ret = value->replaceValue( value, NULL );
            value->free( value );
            inserted = 1;
            break;
        }
        else if ( 0 < e_key->compareTo( e_key, key ) )
        {
            IEntry* entry = (IEntry*) new_StdEntry( key, (IValue*) aValue );
            self->entries->insertBefore( self->entries, p, entry );
            inserted = 1;
            loop = FALSE;
        }
        //int x = e_key->compareTo( e_key, key );
        //fprintf( stdout, "%i %s - %s\n", x, e_key->getChars( e_key ), key->getChars( key ) );
    }
    it->free( it );

    if ( ! inserted )
    {
        IEntry* entry = (IEntry*) new_StdEntry( key, (IValue*) aValue );
        self->entries->insertLast( self->entries, entry );
    }
    return ret;
}