package ocean import "sync" type Collection[T any] interface { Get(key string) (value T, ok bool) } // collection is a hash map of homogeneous data. type collection[T any] struct { data sync.Map name string } // NewCollection creates a new collection with the given name. func NewCollection[T any](name string) *collection[T] { return &collection[T]{name: name} } // Get returns the value for the given key. func (c *collection[T]) Get(key string) (T, bool) { value, exists := c.data.Load(key) return value.(T), exists } // Set sets the value for the given key. func (c *collection[T]) Set(key string, value T) { c.data.Store(key, value) } // Delete deletes a key from the collection. func (c *collection[T]) Delete(key string) { c.data.Delete(key) } // Exists returns whether or not the key exists. func (c *collection[T]) Exists(key string) bool { _, exists := c.data.Load(key) return exists }