func (l *list) Remove(item []byte) bool { | |
key, _ := hashstructure.Hash(item, nil) | |
l.head.lock() | |
pred := l.head | |
curr := pred.next | |
curr.lock() | |
for curr.key < key { | |
pred.unlock() | |
pred = curr | |
curr = curr.next | |
curr.lock() | |
} | |
if curr.key == key { | |
pred.next = curr.next | |
curr.unlock() | |
pred.unlock() | |
l.mu.Lock() | |
l.size-- | |
l.mu.Unlock() | |
return true | |
} | |
curr.unlock() | |
pred.unlock() | |
return false | |
} | |
func (l *list) Contains(item []byte) bool { | |
key, _ := hashstructure.Hash(item, nil) | |
l.head.lock() | |
pred := l.head | |
curr := pred.next | |
curr.lock() | |
for curr.key < key { | |
pred.unlock() | |
pred = curr | |
curr = curr.next | |
curr.lock() | |
} | |
if curr.key == key { | |
pred.unlock() | |
curr.unlock() | |
return true | |
} | |
curr.unlock() | |
pred.unlock() | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment