-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelement.go
52 lines (45 loc) · 1.07 KB
/
element.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package jsonmap
type Key = string
type Value = any
// Element of a map, to be used in iteration.
//
// for elem := m.First(); elem != nil; elem = elem.Next() {
// fmt.Println(elem.Key(), elem.Value())
// }
type Element struct {
key Key
value Value
next, prev *Element
}
// Key returns the key of the element.
//
// key := elem.Key()
func (e *Element) Key() Key {
return e.key
}
// Value returns the value of the element.
//
// value := elem.Value()
func (e *Element) Value() Value {
return e.value
}
// Next returns the next element in the map, for iteration.
// Returns nil if this is the last element.
// O(1) time.
//
// for elem := m.First(); elem != nil; elem = elem.Next() {
// fmt.Println(elem.Key(), elem.Value())
// }
func (e *Element) Next() *Element {
return e.next
}
// Prev returns the previous element in the map, for backwards iteration.
// Returns nil if this is the first element.
// O(1) time.
//
// for elem := m.Last(); elem != nil; elem = elem.Prev() {
// fmt.Println(elem.Key(), elem.Value())
// }
func (e *Element) Prev() *Element {
return e.prev
}