@@ -75,22 +75,40 @@ func (e *expiryHeap[T]) Swap(i, j int) {
7575 e .ents [i ], e .ents [j ] = e .ents [j ], e .ents [i ]
7676}
7777
78+ // Push implements [heap.Interface], adding x to the end of the heap.
79+ // It is plumbing for [container/heap].
80+ //
81+ // Use [heap.Push] instead.
7882func (e * expiryHeap [T ]) Push (x any ) {
7983 xt := x .(expiryHeapEnt [T ])
8084 e .ents = append (e .ents , xt )
8185 xt .updateLocation (len (e .ents ) - 1 )
8286}
8387
88+ // sentinelOffset is used to indicate that an entry is no longer present in the map.
89+ // It will be converted to an int, so it needs to be within the signed range to
90+ // have a directly comparable value.
8491const sentinelOffset = math .MaxInt
8592
93+ // Push implements [heap.Interface], removing and returning the entry at the end of the heap.
94+ // It is plumbing for [container/heap].
95+ //
96+ // Use [heap.Pop] instead.
8697func (e * expiryHeap [T ]) Pop () any {
8798 v := e .ents [len (e .ents )- 1 ]
8899 e .ents = e .ents [:len (e .ents )- 1 ]
89100 v .updateLocation (sentinelOffset )
90101 return v
91102}
92103
104+ // EntryHandle provides a handle for the resource in the heap to allow one to
105+ // remove entries later.
106+ //
107+ // Note: although a pointer to this struct is returned by [ExpiryTracker.Push],
108+ // it's expected that synchronization is handled by the caller.
93109type EntryHandle [T any ] struct {
110+ // note: not atomic because the entire ExpiryTracker requires external
111+ // synchronization anyway.
94112 offset uint
95113}
96114
0 commit comments