Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

HashSet.remove() is broken #24

Closed
gavinking opened this issue Jul 2, 2012 · 2 comments
Closed

HashSet.remove() is broken #24

gavinking opened this issue Jul 2, 2012 · 2 comments
Labels

Comments

@gavinking
Copy link
Contributor

I think this is the correct implementation:

doc "Removes an element from this set, if present"
shared actual void remove(Element element){
    Integer index = storeIndex(element, store);
    variable Cell<Element>? bucket := store[index];
    variable Cell<Element>? prev := null;
    while(exists Cell<Element> cell = bucket){
        if(cell.car == element){
            // found it
            if(exists Cell<Element> last = prev){
                last.cdr := cell.cdr;
            }else{
                store.setItem(index, cell.cdr);
            }
            _size--;
            return;
        }
        bucket := cell.cdr;
        prev := cell;
    }
}
@FroMage
Copy link
Contributor

FroMage commented Jul 27, 2012

Ah, then why didn't you fix it?

FroMage added a commit that referenced this issue Jul 27, 2012
FroMage added a commit that referenced this issue Jul 27, 2012
@FroMage
Copy link
Contributor

FroMage commented Jul 27, 2012

I guess you were shy ;) Now fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants