Skip to content

Instantly share code, notes, and snippets.

@pacuna

pacuna/kpuHJCy8.go

Last active Jun 15, 2020
Embed
What would you like to do?
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