-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtype_funcs.go
More file actions
52 lines (44 loc) · 1011 Bytes
/
type_funcs.go
File metadata and controls
52 lines (44 loc) · 1011 Bytes
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 main
import "fmt"
// Add inserts an entry into the map
func (s *seenStrings) Add(entry string) {
s.mu.Lock()
defer s.mu.Unlock()
s.m[entry] = true
}
// Remove uses delete on the entry in the map
func (s *seenStrings) Remove(entry string) {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.m, entry)
}
// Len returns the length of the map
func (s *seenStrings) Len() int {
s.mu.RLock()
defer s.mu.RUnlock()
return len(s.m)
}
// String implements the Stringer interface
func (s *seenStrings) String() string {
s.mu.RLock()
defer s.mu.RUnlock()
return fmt.Sprint(s.m)
}
// True sets the entry to true
func (s *seenStrings) True(entry string) {
s.mu.Lock()
defer s.mu.Unlock()
s.m[entry] = true
}
// False sets the entry to false
func (s *seenStrings) False(entry string) {
s.mu.Lock()
defer s.mu.Unlock()
delete(s.m, entry)
}
// Exists returns a bool if the map contains the entry
func (s *seenStrings) Exists(entry string) bool {
s.mu.RLock()
defer s.mu.RUnlock()
return s.m[entry]
}