summaryrefslogtreecommitdiff
path: root/nexus/utils/collections/maps.go
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-03-29 22:52:46 +0530
committerBobby <[email protected]>2026-03-29 22:52:46 +0530
commit9eb9b7f4bd552a641235764f66483e1f940fcfd9 (patch)
treeda520b923b5e6758d5457b6233dd6671fc640914 /nexus/utils/collections/maps.go
parent65a143a0871c35989b7c7ea6723d39a0585c089e (diff)
downloadechoes-of-vaelun-main.tar.xz
echoes-of-vaelun-main.zip
feat: nexus account manager scaffold with auth, characters, realmsHEADmain
Diffstat (limited to 'nexus/utils/collections/maps.go')
-rw-r--r--nexus/utils/collections/maps.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/nexus/utils/collections/maps.go b/nexus/utils/collections/maps.go
new file mode 100644
index 0000000..4536515
--- /dev/null
+++ b/nexus/utils/collections/maps.go
@@ -0,0 +1,37 @@
+package collections
+
+type OrderedMap[K comparable, V any] struct {
+ keys []K
+ values map[K]V
+}
+
+func OrderedMapOf[K comparable, V any]() OrderedMap[K, V] {
+ return OrderedMap[K, V]{
+ keys: make([]K, 0),
+ values: make(map[K]V),
+ }
+}
+
+func (self *OrderedMap[K, V]) Set(key K, value V) {
+ if _, exists := self.values[key]; !exists {
+ self.keys = append(self.keys, key)
+ }
+ self.values[key] = value
+}
+
+func (self *OrderedMap[K, V]) Get(key K) (V, bool) {
+ value, exists := self.values[key]
+ return value, exists
+}
+
+func (self *OrderedMap[K, V]) All() []V {
+ result := make([]V, 0, len(self.keys))
+ for _, key := range self.keys {
+ result = append(result, self.values[key])
+ }
+ return result
+}
+
+func (self *OrderedMap[K, V]) Len() int {
+ return len(self.keys)
+}