added string lookup
This commit is contained in:
parent
b47769817e
commit
9955f3feeb
@ -10,7 +10,7 @@ type StringPool struct {
|
||||
counter map[string]uint
|
||||
top uint
|
||||
|
||||
sync.Mutex
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
// NewStringPool creates a new string pool
|
||||
@ -35,6 +35,20 @@ func (p *StringPool) Acquire(s string) *string {
|
||||
return ptr
|
||||
}
|
||||
|
||||
// Get retrieves a pointer to a string, if present.
|
||||
// Otherwise returns nil.
|
||||
func (p *StringPool) Get(s string) *string {
|
||||
p.RLock()
|
||||
defer p.RUnlock()
|
||||
|
||||
// Get value
|
||||
ptr, ok := p.values[s]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return ptr
|
||||
}
|
||||
|
||||
// GarbageCollect releases all values, which have not been seen
|
||||
// again.
|
||||
func (p *StringPool) GarbageCollect() uint {
|
||||
|
Loading…
x
Reference in New Issue
Block a user