Documentation ¶
Overview ¶
Package stamp contains a utility for maintaining certain ordering invariants when queuing (time-)stamped values.
Index ¶
- func Compare(a, b Stamp) int
- type Coalescing
- type MinMap
- type Queue
- func (s *Queue) Consistent() Stamp
- func (s *Queue) Dequeue() Stamped
- func (s *Queue) Enqueue(next Stamped) error
- func (s *Queue) Mark(marker Stamp) error
- func (s *Queue) Markers(buf []Stamp) []Stamp
- func (s *Queue) Peek() Stamped
- func (s *Queue) PeekMarker() Stamp
- func (s *Queue) Values(buf []Stamped) []Stamped
- type Stamp
- type Stamped
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Coalescing ¶
type Coalescing interface { Stamped // Coalesce may be implemented to allow the tail node in the queue // to be coalesced with some proposed value to be added to the end // of the queue. Implementations should modify the callee as // appropriate to append the next tail value. This method can return // an alternate, non-nil value to still be added to the queue. If // this method returns nil, then the tail value will be considered // to have been fully coalesced and no new value will be added to // the queue. Coalesce(tail Stamped) (remainder Stamped) }
Coalescing is an optional interface that may be implemented by Stamped values.
type MinMap ¶
type MinMap struct {
// contains filtered or unexported fields
}
A MinMap provides a mapping of keys to Stamp values, while also tracking the minimum value.
A MinMap is not internally synchronized. A MinMap should not be copied once created.
func (*MinMap) Get ¶
Get returns the previously set Stamp for the key, or nil if no mapping is present.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue maintains ordered Stamped values.
Draining values from the queue advances a "consistent point", derived from the stamps of the dequeued values and a queue of candidate, "marker" stamps. The lowest-valued marker becomes the consistent point when there are no more stamped values in the queue whose stamps are less than the marker.
Queue is not internally synchronized. The zero value is ready to use. A Queue should not be copied once created.
At present, this implementation assumes that it is being driven from a serial source of data that provides monotonic stamps. It would be possible to extend the behavior to allow for out-of-order insertion, albeit with increased algorithmic complexity, provided that the stamp of the enqueued value is still greater than the consistent point.
The following Stamp-ordering invariants are maintained:
- values[0] <= values[1] ... <= values[n] (softly monotonic)
- markers[0] < markers[1] ... < markers[n] (strictly monotonic)
- consistent < values[0]
- consistent < markers[0]
- consistent > previousConsistent.
func (*Queue) Consistent ¶
Consistent returns a Stamp which is less than the stamps of all enqueued values or markers. This value will be nil if none of Dequeue, Mark, or setConsistent have been called.
func (*Queue) Dequeue ¶
Dequeue returns the next Stamped value, or nil if the Queue is empty. Draining a value will advance the consistent point to the greatest marker that is strictly less than the Stamp of the value returned. That is, the consistent Stamp will be in the half-open range of [ nil, Dequeue().Stamp() ).
func (*Queue) Enqueue ¶
Enqueue adds a Stamped value to the end of the queue. If the tail value in the Queue implements Coalescing, the Queue will attempt to merge the tail and next values.
func (*Queue) Mark ¶
Mark adds a potential future consistent point to the Queue. This method will update the consistent point if the new marker is greater than the current consistent point and less than the stamp of the head of the queue or if the queue is empty.
func (*Queue) Markers ¶
Markers appends all markers passed to Mark that are greater than the current consistent point. The modified slice is returned.
func (*Queue) PeekMarker ¶
PeekMarker returns the head of the markers queue, without modifying it.