func NewMapWithProvider(capacity int, timeProvider timetools.TimeProvider) (*TtlMap, error) { if capacity <= 0 { return nil, fmt.Errorf("Capacity should be > 0") } if timeProvider == nil { return nil, fmt.Errorf("Please pass timeProvider") } return &TtlMap{ capacity: capacity, elements: make(map[string]*mapElement), expiryTimes: minheap.NewMinHeap(), TimeProvider: timeProvider, }, nil }
func NewMap(capacity int, opts ...TtlMapOption) (*TtlMap, error) { if capacity <= 0 { return nil, errors.New("Capacity should be > 0") } m := &TtlMap{ capacity: capacity, elements: make(map[string]*mapElement), expiryTimes: minheap.NewMinHeap(), } for _, o := range opts { if err := o(m); err != nil { return nil, err } } if m.clock == nil { m.clock = &timetools.RealTime{} } return m, nil }
func newCursorMap() *cursorMap { return &cursorMap{ cursors: make(map[uint32][]*cursor), expiryTimes: minheap.NewMinHeap(), } }