package sequence import ( "math" "sync" ) // default Sequencer type MemorySequencer struct { counter uint64 sequenceLock sync.Mutex } func NewMemorySequencer() (m *MemorySequencer) { m = &MemorySequencer{counter: 1} return } func (m *MemorySequencer) NextFileId(count uint64) uint64 { m.sequenceLock.Lock() defer m.sequenceLock.Unlock() ret := m.counter // stays at the largest id rather than wrapping back to ids handed out m.counter += min(count, math.MaxUint64-m.counter) return ret } func (m *MemorySequencer) SetMax(seenValue uint64) { m.sequenceLock.Lock() defer m.sequenceLock.Unlock() if m.counter <= seenValue { m.counter = min(seenValue, math.MaxUint64-1) + 1 } }