From ad7103ecdc097f7f122982dd448ea62f0439da46 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 10 Sep 2012 09:14:17 +0200 Subject: [PATCH] Add FindFunc --- zone.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/zone.go b/zone.go index 50ed0d55..9d10f63e 100644 --- a/zone.go +++ b/zone.go @@ -68,8 +68,8 @@ type ZoneData struct { RR map[uint16][]RR // Map of the RR type to the RR Signatures map[uint16][]*RR_RRSIG // DNSSEC signatures for the RRs, stored under type covered NonAuth bool // Always false, except for NSsets that differ from z.Origin - mutex *sync.RWMutex // For locking - radix *radix.Radix // The actual radix node belonging to this value + mutex *sync.RWMutex // For locking + radix *radix.Radix // The actual radix node belonging to this value } // newZoneData creates a new zone data element @@ -213,6 +213,19 @@ func (z *Zone) Find(s string) (*ZoneData, bool) { return zd.Value.(*ZoneData), e } +// FindFunc works like Find, but the function f is executed on +// each node which has a non-nil Value during the tree traversel. +// If f returns true, that node is returned. +func (z *Zone) FindFunc(s string, f func(interface{}) bool) (*ZoneData, bool, bool) { + z.mutex.RLock() + defer z.mutex.RUnlock() + zd, e, b := z.Radix.FindFunc(toRadixName(s), f) + if zd == nil { + return nil, false, false + } + return zd.Value.(*ZoneData), e, b +} + // Up bla bla func (z *Zone) Up(s string) *ZoneData { z.mutex.RLock()