Skip to content

Commit

Permalink
Entries.filter and delete basically do the same thing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Jul 14, 2015
1 parent 4f6a214 commit 36ec2c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
14 changes: 2 additions & 12 deletions nameserver/entry.go
Expand Up @@ -122,16 +122,6 @@ func (es *Entries) merge(incoming Entries) Entries {
return newEntries
}

func (es *Entries) filter(f func(*Entry) bool) {
var result Entries
for _, e := range *es {
if f(&e) {
result = append(result, e)
}
}
*es = result
}

func (es *Entries) tombstone(ourname router.PeerName, f func(*Entry) bool) *Entries {
tombstoned := Entries{}
for i, e := range *es {
Expand All @@ -145,10 +135,10 @@ func (es *Entries) tombstone(ourname router.PeerName, f func(*Entry) bool) *Entr
return &tombstoned
}

func (es *Entries) delete(f func(*Entry) bool) {
func (es *Entries) filter(f func(*Entry) bool) {
i := 0
for _, e := range *es {
if f(&e) {
if !f(&e) {
continue
}
(*es)[i] = e
Expand Down
4 changes: 2 additions & 2 deletions nameserver/entry_test.go
Expand Up @@ -87,8 +87,8 @@ func TestDelete(t *testing.T) {
Entry{Hostname: "B"},
}

es.delete(func(e *Entry) bool {
return e.Hostname == "A"
es.filter(func(e *Entry) bool {
return e.Hostname != "A"
})
expected := Entries{
Entry{Hostname: "B"},
Expand Down
8 changes: 4 additions & 4 deletions nameserver/nameserver.go
Expand Up @@ -139,8 +139,8 @@ func (n *Nameserver) ContainerDied(ident string) error {
func (n *Nameserver) PeerGone(peer *router.Peer) {
n.Lock()
defer n.Unlock()
n.entries.delete(func(e *Entry) bool {
return e.Origin == peer.Name
n.entries.filter(func(e *Entry) bool {
return e.Origin != peer.Name
})
}

Expand Down Expand Up @@ -172,8 +172,8 @@ func (n *Nameserver) deleteTombstones() {
n.Lock()
defer n.Unlock()
now := time.Now().Unix()
n.entries.delete(func(e *Entry) bool {
return now-e.Tombstone > int64(tombstoneTimeout/time.Second)
n.entries.filter(func(e *Entry) bool {
return now-e.Tombstone <= int64(tombstoneTimeout/time.Second)
})
}

Expand Down

0 comments on commit 36ec2c7

Please sign in to comment.