|
|
@@ -7,8 +7,8 @@ import (
|
|
|
// A pool of vector maps for mapping float64 timestamps
|
|
|
// to float64 values
|
|
|
type VectorMapPool interface {
|
|
|
- Get() map[float64]float64
|
|
|
- Put(map[float64]float64)
|
|
|
+ Get() map[uint64]float64
|
|
|
+ Put(map[uint64]float64)
|
|
|
}
|
|
|
|
|
|
// ------------
|
|
|
@@ -19,17 +19,17 @@ type VectorMapPool interface {
|
|
|
// maps will block until one is available. You will be unable to
|
|
|
// Put() a map if the buffer is full.
|
|
|
type FixedMapPool struct {
|
|
|
- maps chan map[float64]float64
|
|
|
+ maps chan map[uint64]float64
|
|
|
size int
|
|
|
}
|
|
|
|
|
|
// Returns a map from the pool. Blocks if no maps are available for re-use
|
|
|
-func (mp *FixedMapPool) Get() map[float64]float64 {
|
|
|
+func (mp *FixedMapPool) Get() map[uint64]float64 {
|
|
|
return <-mp.maps
|
|
|
}
|
|
|
|
|
|
// Adds a map back to the pool if there is room. Does not block on overflow.
|
|
|
-func (mp *FixedMapPool) Put(m map[float64]float64) {
|
|
|
+func (mp *FixedMapPool) Put(m map[uint64]float64) {
|
|
|
if len(mp.maps) >= mp.size {
|
|
|
return
|
|
|
}
|
|
|
@@ -44,13 +44,13 @@ func (mp *FixedMapPool) Put(m map[float64]float64) {
|
|
|
// Creates a new fixed map pool which maintains a fixed pool size
|
|
|
func NewFixedMapPool(size int) VectorMapPool {
|
|
|
mp := &FixedMapPool{
|
|
|
- maps: make(chan map[float64]float64, size),
|
|
|
+ maps: make(chan map[uint64]float64, size),
|
|
|
size: size,
|
|
|
}
|
|
|
|
|
|
// Pre-Populate the buffer with maps
|
|
|
for i := 0; i < size; i++ {
|
|
|
- mp.maps <- make(map[float64]float64)
|
|
|
+ mp.maps <- make(map[uint64]float64)
|
|
|
}
|
|
|
|
|
|
return mp
|
|
|
@@ -64,21 +64,21 @@ func NewFixedMapPool(size int) VectorMapPool {
|
|
|
// not block if maps are over requested, but will only maintain
|
|
|
// a buffer up the size limitation.
|
|
|
type FlexibleMapPool struct {
|
|
|
- maps chan map[float64]float64
|
|
|
+ maps chan map[uint64]float64
|
|
|
}
|
|
|
|
|
|
// Returns a map from the pool. Does not block on over-request.
|
|
|
-func (mp *FlexibleMapPool) Get() map[float64]float64 {
|
|
|
+func (mp *FlexibleMapPool) Get() map[uint64]float64 {
|
|
|
select {
|
|
|
case m := <-mp.maps:
|
|
|
return m
|
|
|
default:
|
|
|
- return make(map[float64]float64)
|
|
|
+ return make(map[uint64]float64)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Adds a map back to the pool if there is room. Does not block on overflow.
|
|
|
-func (mp *FlexibleMapPool) Put(m map[float64]float64) {
|
|
|
+func (mp *FlexibleMapPool) Put(m map[uint64]float64) {
|
|
|
for k := range m {
|
|
|
delete(m, k)
|
|
|
}
|
|
|
@@ -86,14 +86,16 @@ func (mp *FlexibleMapPool) Put(m map[float64]float64) {
|
|
|
// Either return the map to the buffered channel, or do nothing
|
|
|
select {
|
|
|
case mp.maps <- m:
|
|
|
+ return
|
|
|
default:
|
|
|
+ return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Creates a new fixed map pool which maintains a fixed pool size
|
|
|
func NewFlexibleMapPool(size int) VectorMapPool {
|
|
|
return &FlexibleMapPool{
|
|
|
- maps: make(chan map[float64]float64, size),
|
|
|
+ maps: make(chan map[uint64]float64, size),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -105,12 +107,12 @@ type UnboundedMapPool struct {
|
|
|
}
|
|
|
|
|
|
// Returns a map from the pool. Does not block on over-request.
|
|
|
-func (mp *UnboundedMapPool) Get() map[float64]float64 {
|
|
|
- return mp.maps.Get().(map[float64]float64)
|
|
|
+func (mp *UnboundedMapPool) Get() map[uint64]float64 {
|
|
|
+ return mp.maps.Get().(map[uint64]float64)
|
|
|
}
|
|
|
|
|
|
// Adds a map back to the pool if there is room. Does not block on overflow.
|
|
|
-func (mp *UnboundedMapPool) Put(m map[float64]float64) {
|
|
|
+func (mp *UnboundedMapPool) Put(m map[uint64]float64) {
|
|
|
for k := range m {
|
|
|
delete(m, k)
|
|
|
}
|
|
|
@@ -124,7 +126,7 @@ func NewUnboundedMapPool() VectorMapPool {
|
|
|
return &UnboundedMapPool{
|
|
|
maps: &sync.Pool{
|
|
|
New: func() interface{} {
|
|
|
- return make(map[float64]float64)
|
|
|
+ return make(map[uint64]float64)
|
|
|
},
|
|
|
},
|
|
|
}
|