This repository was archived by the owner on Nov 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps.go
More file actions
65 lines (50 loc) · 1.96 KB
/
maps.go
File metadata and controls
65 lines (50 loc) · 1.96 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
// This implementation is inspired by Apache Commons Collections
// (licensed under the Apache License, Version 2.0).
package orderedmap
import "iter"
// MaxCapacity defines the maximum number of elements
// the map can hold. It is set to 2^30 to prevent excessive memory usage.
const MaxCapacity = 1 << 30
// DefaultCapacity is the initial capacity of the map
// when no specific size is provided. Typical default is 16.
const DefaultCapacity = 16
// DefaultLoadFactor determines when the map should grow
// (rehash). A load factor of 0.75 means the map will resize
// when 75% full.
const DefaultLoadFactor = 0.75
// Map is a generic interface for an ordered map that preserves
// the insertion order of keys. It supports basic map operations,
// iteration, and cloning.
//
// K - key type
// V - value type
type Map[K, V any] interface {
// Size returns the number of elements in the map.
Size() int
// IsEmpty returns true if the map contains no elements.
IsEmpty() bool
// Clear removes all elements from the map.
Clear()
// Clone creates a shallow copy of the map.
Clone() Map[K, V]
// Get returns the value associated with the given key
// and a boolean indicating if the key exists.
Get(K) (V, bool)
// Put inserts or updates the value for a key. It returns
// the previous value and a boolean indicating if the key existed.
Put(K, V) (V, bool)
// Delete removes the key from the map. Returns the value
// and a boolean indicating if the key existed.
Delete(K) (V, bool)
// Keys returns a sequence of keys in insertion order.
Keys() iter.Seq[K]
// Values returns a sequence of values in insertion order.
Values() iter.Seq[V]
// Items returns a sequence of key-value pairs in insertion order.
Items() iter.Seq2[K, V]
}
// Integer is a type constraint for all built-in integer types.
// It includes both signed and unsigned integers of all sizes.
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}