Debian Codegraph @

model/orderedmap/map.go

raw symbols SCIP
1 package orderedmapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/
2
3 import (
4 "reflectscip-go gomod github.com/golang/go/src go1.25 reflect/"
5 )
6
7 // KeyValue is a single key value pair from a *Map.
8 type KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue# struct {
9 Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Key. string
10 Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Value. any
11 }
12
13 // NewMap returns a new *Map that has its values initialised.
14 func NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().() *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map# {
15 keys := make([]string, 0)
16 data := make(map[string]any)
17 return &Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#{
18 keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys.: keys,
19 datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.: data,
20 }
21 }
22
23 // FromMap creates a *Map from the input map.
24 // Note that while the contents will be ordered, the ordering is not
25 // guaranteed since the input map is unordered.
26 func FromMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/FromMap().(source map[string]any) *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map# {
27 m := NewMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/NewMap().()
28 for k, v := range source {
29 m.Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().(k, v)
30 }
31 return m
32 }
33
34 // Map is a map implementation that maintains ordering of keys.
35 type Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map# struct {
36 // keys contains the keys within the map in the order they were added.
37 keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys. []string
38 // data contains the actual map data.
39 datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data. map[string]any
40 }
41
42 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() int {
43 return len(m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys.)
44 }
45
46 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) Equalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Equal().(other *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) bool {
47 if m.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() != other.Lenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Len().() {
48 return false
49 }
50
51 for i, k := range m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys. {
52 if k != other.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys.[i] {
53 return false
54 }
55
56 if !reflectscip-go gomod github.com/golang/go/src go1.25 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25 reflect/DeepEqual().(m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.[k], other.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.[k]) {
57 return false
58 }
59 }
60
61 return true
62 }
63
64 // Get returns the value found under the given key.
65 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) Getscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Get().(key string) (any, bool) {
66 v, ok := m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.[key]
67 return v, ok
68 }
69
70 // Set sets a value under the given key.
71 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) Setscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Set().(key string, value any) *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map# {
72 if _, ok := m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.[key]; ok {
73 m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.[key] = value
74 } else {
75 m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys. = append(m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys., key)
76 m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.[key] = value
77 }
78 return m
79 }
80
81 // Delete deletes the value found under the given key.
82 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) Deletescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Delete().(key string) *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map# {
83 // Delete the data entry.
84 delete(m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data., key)
85
86 // Remove the item from the keys.
87 foundIndex := -1
88 for i, k := range m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys. {
89 if k == key {
90 foundIndex = i
91 break
92 }
93 }
94
95 if foundIndex >= 0 {
96 m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys. = append((m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys.)[:foundIndex], (m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys.)[foundIndex+1:]...)
97 }
98
99 return m
100 }
101
102 // KeyValues returns the KeyValue pairs within the map, in the order that they were added.
103 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) KeyValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#KeyValues().() []KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue# {
104 res := make([]KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#, 0)
105 for _, key := range m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys. {
106 res = append(res, KeyValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#{
107 Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Key.: key,
108 Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/KeyValue#Value.: m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.[key],
109 })
110 }
111 return res
112 }
113
114 // Keys returns all the keys from the map.
115 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) Keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#Keys().() []string {
116 return m.keysscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#keys.
117 }
118
119 // UnorderedData returns all the data from the map.
120 func (m *Mapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#) UnorderedDatascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#UnorderedData().() map[string]any {
121 return m.datascip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model/orderedmap`/Map#data.
122 }