This commit is contained in:
2026-02-19 10:07:43 +00:00
parent 007438e372
commit 6e637ecf77
1763 changed files with 60820 additions and 279516 deletions

View File

@@ -9,20 +9,28 @@ package set
type HandleSet[T any] map[Handle]T
// Handle is an opaque comparable value that's used as the map key in a
// HandleSet. The only way to get one is to call HandleSet.Add.
// HandleSet.
type Handle struct {
v *byte
}
// NewHandle returns a new handle value.
func NewHandle() Handle {
return Handle{new(byte)}
}
// Add adds the element (map value) e to the set.
//
// It returns the handle (map key) with which e can be removed, using a map
// delete.
// It returns a new handle (map key) with which e can be removed, using a map
// delete or the [HandleSet.Delete] method.
func (s *HandleSet[T]) Add(e T) Handle {
h := Handle{new(byte)}
h := NewHandle()
if *s == nil {
*s = make(HandleSet[T])
}
(*s)[h] = e
return h
}
// Delete removes the element with handle h from the set.
func (s HandleSet[T]) Delete(h Handle) { delete(s, h) }