Skip to content

Instantly share code, notes, and snippets.

@pacuna
Last active June 15, 2020 01:11
Show Gist options
  • Save pacuna/0626e9b956e27737b387ccc0e418682e to your computer and use it in GitHub Desktop.
Save pacuna/0626e9b956e27737b387ccc0e418682e to your computer and use it in GitHub Desktop.
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