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