Skip to content

Instantly share code, notes, and snippets.

@pacuna

pacuna/eaU5rn8d.go

Last active Jun 15, 2020
Embed
What would you like to do?
func (l *list) Add(item []byte) bool {
var pred, curr *node
key, _ := hashstructure.Hash(item, nil)
l.mu.Lock()
defer l.mu.Unlock()
pred = l.head
curr = pred.next
for curr.key < key {
pred = curr
curr = curr.next
}
if key == curr.key {
return false
}
n := newNode(item)
n.next = curr
pred.next = n
l.size++
return true
}
func (l *list) Remove(item []byte) bool {
var pred, curr *node
key, _ := hashstructure.Hash(item, nil)
l.mu.Lock()
defer l.mu.Unlock()
pred = l.head
curr = pred.next
for curr.key < key {
pred = curr
curr = curr.next
}
if key == curr.key {
pred.next = curr.next
return true
}
return false
}
func (l *list) Contains(item []byte) bool {
var pred, curr *node
key, _ := hashstructure.Hash(item, nil)
l.mu.Lock()
defer l.mu.Unlock()
pred = l.head
curr = pred.next
for curr.key < key {
pred = curr
curr = curr.next
}
return key == curr.key
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.