Skip to content

Commit ff067cf

Browse files
committed
lib: utility functions for manipulating sets of primitive type
elements represented using maps I have seen multiple implementations of string sets and integer sets and methods the perform set operation and convert between sets and slices. This CL provides a comprehensive set of reusable utility functions for handling sets. NOTE: Most of the code in this CL is auto-generated; focus your review efforts on doc.go and gen.go. Change-Id: If8def2d905264a26c75fa63a600dae498a42601b
1 parent 2ab4d05 commit ff067cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+8733
-0
lines changed

set/.api

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
pkg set, method (Complex128BoolT) Difference(map[complex128]bool, map[complex128]bool)
2+
pkg set, method (Complex128BoolT) FromSlice([]complex128) map[complex128]bool
3+
pkg set, method (Complex128BoolT) Intersection(map[complex128]bool, map[complex128]bool)
4+
pkg set, method (Complex128BoolT) ToSlice(map[complex128]bool) []complex128
5+
pkg set, method (Complex128BoolT) Union(map[complex128]bool, map[complex128]bool)
6+
pkg set, method (Complex128T) Difference(map[complex128]struct{}, map[complex128]struct{})
7+
pkg set, method (Complex128T) FromSlice([]complex128) map[complex128]struct{}
8+
pkg set, method (Complex128T) Intersection(map[complex128]struct{}, map[complex128]struct{})
9+
pkg set, method (Complex128T) ToSlice(map[complex128]struct{}) []complex128
10+
pkg set, method (Complex128T) Union(map[complex128]struct{}, map[complex128]struct{})
11+
pkg set, method (Complex64BoolT) Difference(map[complex64]bool, map[complex64]bool)
12+
pkg set, method (Complex64BoolT) FromSlice([]complex64) map[complex64]bool
13+
pkg set, method (Complex64BoolT) Intersection(map[complex64]bool, map[complex64]bool)
14+
pkg set, method (Complex64BoolT) ToSlice(map[complex64]bool) []complex64
15+
pkg set, method (Complex64BoolT) Union(map[complex64]bool, map[complex64]bool)
16+
pkg set, method (Complex64T) Difference(map[complex64]struct{}, map[complex64]struct{})
17+
pkg set, method (Complex64T) FromSlice([]complex64) map[complex64]struct{}
18+
pkg set, method (Complex64T) Intersection(map[complex64]struct{}, map[complex64]struct{})
19+
pkg set, method (Complex64T) ToSlice(map[complex64]struct{}) []complex64
20+
pkg set, method (Complex64T) Union(map[complex64]struct{}, map[complex64]struct{})
21+
pkg set, method (Float32BoolT) Difference(map[float32]bool, map[float32]bool)
22+
pkg set, method (Float32BoolT) FromSlice([]float32) map[float32]bool
23+
pkg set, method (Float32BoolT) Intersection(map[float32]bool, map[float32]bool)
24+
pkg set, method (Float32BoolT) ToSlice(map[float32]bool) []float32
25+
pkg set, method (Float32BoolT) Union(map[float32]bool, map[float32]bool)
26+
pkg set, method (Float32T) Difference(map[float32]struct{}, map[float32]struct{})
27+
pkg set, method (Float32T) FromSlice([]float32) map[float32]struct{}
28+
pkg set, method (Float32T) Intersection(map[float32]struct{}, map[float32]struct{})
29+
pkg set, method (Float32T) ToSlice(map[float32]struct{}) []float32
30+
pkg set, method (Float32T) Union(map[float32]struct{}, map[float32]struct{})
31+
pkg set, method (Float64BoolT) Difference(map[float64]bool, map[float64]bool)
32+
pkg set, method (Float64BoolT) FromSlice([]float64) map[float64]bool
33+
pkg set, method (Float64BoolT) Intersection(map[float64]bool, map[float64]bool)
34+
pkg set, method (Float64BoolT) ToSlice(map[float64]bool) []float64
35+
pkg set, method (Float64BoolT) Union(map[float64]bool, map[float64]bool)
36+
pkg set, method (Float64T) Difference(map[float64]struct{}, map[float64]struct{})
37+
pkg set, method (Float64T) FromSlice([]float64) map[float64]struct{}
38+
pkg set, method (Float64T) Intersection(map[float64]struct{}, map[float64]struct{})
39+
pkg set, method (Float64T) ToSlice(map[float64]struct{}) []float64
40+
pkg set, method (Float64T) Union(map[float64]struct{}, map[float64]struct{})
41+
pkg set, method (Int16BoolT) Difference(map[int16]bool, map[int16]bool)
42+
pkg set, method (Int16BoolT) FromSlice([]int16) map[int16]bool
43+
pkg set, method (Int16BoolT) Intersection(map[int16]bool, map[int16]bool)
44+
pkg set, method (Int16BoolT) ToSlice(map[int16]bool) []int16
45+
pkg set, method (Int16BoolT) Union(map[int16]bool, map[int16]bool)
46+
pkg set, method (Int16T) Difference(map[int16]struct{}, map[int16]struct{})
47+
pkg set, method (Int16T) FromSlice([]int16) map[int16]struct{}
48+
pkg set, method (Int16T) Intersection(map[int16]struct{}, map[int16]struct{})
49+
pkg set, method (Int16T) ToSlice(map[int16]struct{}) []int16
50+
pkg set, method (Int16T) Union(map[int16]struct{}, map[int16]struct{})
51+
pkg set, method (Int32BoolT) Difference(map[int32]bool, map[int32]bool)
52+
pkg set, method (Int32BoolT) FromSlice([]int32) map[int32]bool
53+
pkg set, method (Int32BoolT) Intersection(map[int32]bool, map[int32]bool)
54+
pkg set, method (Int32BoolT) ToSlice(map[int32]bool) []int32
55+
pkg set, method (Int32BoolT) Union(map[int32]bool, map[int32]bool)
56+
pkg set, method (Int32T) Difference(map[int32]struct{}, map[int32]struct{})
57+
pkg set, method (Int32T) FromSlice([]int32) map[int32]struct{}
58+
pkg set, method (Int32T) Intersection(map[int32]struct{}, map[int32]struct{})
59+
pkg set, method (Int32T) ToSlice(map[int32]struct{}) []int32
60+
pkg set, method (Int32T) Union(map[int32]struct{}, map[int32]struct{})
61+
pkg set, method (Int64BoolT) Difference(map[int64]bool, map[int64]bool)
62+
pkg set, method (Int64BoolT) FromSlice([]int64) map[int64]bool
63+
pkg set, method (Int64BoolT) Intersection(map[int64]bool, map[int64]bool)
64+
pkg set, method (Int64BoolT) ToSlice(map[int64]bool) []int64
65+
pkg set, method (Int64BoolT) Union(map[int64]bool, map[int64]bool)
66+
pkg set, method (Int64T) Difference(map[int64]struct{}, map[int64]struct{})
67+
pkg set, method (Int64T) FromSlice([]int64) map[int64]struct{}
68+
pkg set, method (Int64T) Intersection(map[int64]struct{}, map[int64]struct{})
69+
pkg set, method (Int64T) ToSlice(map[int64]struct{}) []int64
70+
pkg set, method (Int64T) Union(map[int64]struct{}, map[int64]struct{})
71+
pkg set, method (Int8BoolT) Difference(map[int8]bool, map[int8]bool)
72+
pkg set, method (Int8BoolT) FromSlice([]int8) map[int8]bool
73+
pkg set, method (Int8BoolT) Intersection(map[int8]bool, map[int8]bool)
74+
pkg set, method (Int8BoolT) ToSlice(map[int8]bool) []int8
75+
pkg set, method (Int8BoolT) Union(map[int8]bool, map[int8]bool)
76+
pkg set, method (Int8T) Difference(map[int8]struct{}, map[int8]struct{})
77+
pkg set, method (Int8T) FromSlice([]int8) map[int8]struct{}
78+
pkg set, method (Int8T) Intersection(map[int8]struct{}, map[int8]struct{})
79+
pkg set, method (Int8T) ToSlice(map[int8]struct{}) []int8
80+
pkg set, method (Int8T) Union(map[int8]struct{}, map[int8]struct{})
81+
pkg set, method (IntBoolT) Difference(map[int]bool, map[int]bool)
82+
pkg set, method (IntBoolT) FromSlice([]int) map[int]bool
83+
pkg set, method (IntBoolT) Intersection(map[int]bool, map[int]bool)
84+
pkg set, method (IntBoolT) ToSlice(map[int]bool) []int
85+
pkg set, method (IntBoolT) Union(map[int]bool, map[int]bool)
86+
pkg set, method (IntT) Difference(map[int]struct{}, map[int]struct{})
87+
pkg set, method (IntT) FromSlice([]int) map[int]struct{}
88+
pkg set, method (IntT) Intersection(map[int]struct{}, map[int]struct{})
89+
pkg set, method (IntT) ToSlice(map[int]struct{}) []int
90+
pkg set, method (IntT) Union(map[int]struct{}, map[int]struct{})
91+
pkg set, method (StringBoolT) Difference(map[string]bool, map[string]bool)
92+
pkg set, method (StringBoolT) FromSlice([]string) map[string]bool
93+
pkg set, method (StringBoolT) Intersection(map[string]bool, map[string]bool)
94+
pkg set, method (StringBoolT) ToSlice(map[string]bool) []string
95+
pkg set, method (StringBoolT) Union(map[string]bool, map[string]bool)
96+
pkg set, method (StringT) Difference(map[string]struct{}, map[string]struct{})
97+
pkg set, method (StringT) FromSlice([]string) map[string]struct{}
98+
pkg set, method (StringT) Intersection(map[string]struct{}, map[string]struct{})
99+
pkg set, method (StringT) ToSlice(map[string]struct{}) []string
100+
pkg set, method (StringT) Union(map[string]struct{}, map[string]struct{})
101+
pkg set, method (Uint16BoolT) Difference(map[uint16]bool, map[uint16]bool)
102+
pkg set, method (Uint16BoolT) FromSlice([]uint16) map[uint16]bool
103+
pkg set, method (Uint16BoolT) Intersection(map[uint16]bool, map[uint16]bool)
104+
pkg set, method (Uint16BoolT) ToSlice(map[uint16]bool) []uint16
105+
pkg set, method (Uint16BoolT) Union(map[uint16]bool, map[uint16]bool)
106+
pkg set, method (Uint16T) Difference(map[uint16]struct{}, map[uint16]struct{})
107+
pkg set, method (Uint16T) FromSlice([]uint16) map[uint16]struct{}
108+
pkg set, method (Uint16T) Intersection(map[uint16]struct{}, map[uint16]struct{})
109+
pkg set, method (Uint16T) ToSlice(map[uint16]struct{}) []uint16
110+
pkg set, method (Uint16T) Union(map[uint16]struct{}, map[uint16]struct{})
111+
pkg set, method (Uint32BoolT) Difference(map[uint32]bool, map[uint32]bool)
112+
pkg set, method (Uint32BoolT) FromSlice([]uint32) map[uint32]bool
113+
pkg set, method (Uint32BoolT) Intersection(map[uint32]bool, map[uint32]bool)
114+
pkg set, method (Uint32BoolT) ToSlice(map[uint32]bool) []uint32
115+
pkg set, method (Uint32BoolT) Union(map[uint32]bool, map[uint32]bool)
116+
pkg set, method (Uint32T) Difference(map[uint32]struct{}, map[uint32]struct{})
117+
pkg set, method (Uint32T) FromSlice([]uint32) map[uint32]struct{}
118+
pkg set, method (Uint32T) Intersection(map[uint32]struct{}, map[uint32]struct{})
119+
pkg set, method (Uint32T) ToSlice(map[uint32]struct{}) []uint32
120+
pkg set, method (Uint32T) Union(map[uint32]struct{}, map[uint32]struct{})
121+
pkg set, method (Uint64BoolT) Difference(map[uint64]bool, map[uint64]bool)
122+
pkg set, method (Uint64BoolT) FromSlice([]uint64) map[uint64]bool
123+
pkg set, method (Uint64BoolT) Intersection(map[uint64]bool, map[uint64]bool)
124+
pkg set, method (Uint64BoolT) ToSlice(map[uint64]bool) []uint64
125+
pkg set, method (Uint64BoolT) Union(map[uint64]bool, map[uint64]bool)
126+
pkg set, method (Uint64T) Difference(map[uint64]struct{}, map[uint64]struct{})
127+
pkg set, method (Uint64T) FromSlice([]uint64) map[uint64]struct{}
128+
pkg set, method (Uint64T) Intersection(map[uint64]struct{}, map[uint64]struct{})
129+
pkg set, method (Uint64T) ToSlice(map[uint64]struct{}) []uint64
130+
pkg set, method (Uint64T) Union(map[uint64]struct{}, map[uint64]struct{})
131+
pkg set, method (Uint8BoolT) Difference(map[uint8]bool, map[uint8]bool)
132+
pkg set, method (Uint8BoolT) FromSlice([]uint8) map[uint8]bool
133+
pkg set, method (Uint8BoolT) Intersection(map[uint8]bool, map[uint8]bool)
134+
pkg set, method (Uint8BoolT) ToSlice(map[uint8]bool) []uint8
135+
pkg set, method (Uint8BoolT) Union(map[uint8]bool, map[uint8]bool)
136+
pkg set, method (Uint8T) Difference(map[uint8]struct{}, map[uint8]struct{})
137+
pkg set, method (Uint8T) FromSlice([]uint8) map[uint8]struct{}
138+
pkg set, method (Uint8T) Intersection(map[uint8]struct{}, map[uint8]struct{})
139+
pkg set, method (Uint8T) ToSlice(map[uint8]struct{}) []uint8
140+
pkg set, method (Uint8T) Union(map[uint8]struct{}, map[uint8]struct{})
141+
pkg set, method (UintBoolT) Difference(map[uint]bool, map[uint]bool)
142+
pkg set, method (UintBoolT) FromSlice([]uint) map[uint]bool
143+
pkg set, method (UintBoolT) Intersection(map[uint]bool, map[uint]bool)
144+
pkg set, method (UintBoolT) ToSlice(map[uint]bool) []uint
145+
pkg set, method (UintBoolT) Union(map[uint]bool, map[uint]bool)
146+
pkg set, method (UintT) Difference(map[uint]struct{}, map[uint]struct{})
147+
pkg set, method (UintT) FromSlice([]uint) map[uint]struct{}
148+
pkg set, method (UintT) Intersection(map[uint]struct{}, map[uint]struct{})
149+
pkg set, method (UintT) ToSlice(map[uint]struct{}) []uint
150+
pkg set, method (UintT) Union(map[uint]struct{}, map[uint]struct{})
151+
pkg set, method (UintptrBoolT) Difference(map[uintptr]bool, map[uintptr]bool)
152+
pkg set, method (UintptrBoolT) FromSlice([]uintptr) map[uintptr]bool
153+
pkg set, method (UintptrBoolT) Intersection(map[uintptr]bool, map[uintptr]bool)
154+
pkg set, method (UintptrBoolT) ToSlice(map[uintptr]bool) []uintptr
155+
pkg set, method (UintptrBoolT) Union(map[uintptr]bool, map[uintptr]bool)
156+
pkg set, method (UintptrT) Difference(map[uintptr]struct{}, map[uintptr]struct{})
157+
pkg set, method (UintptrT) FromSlice([]uintptr) map[uintptr]struct{}
158+
pkg set, method (UintptrT) Intersection(map[uintptr]struct{}, map[uintptr]struct{})
159+
pkg set, method (UintptrT) ToSlice(map[uintptr]struct{}) []uintptr
160+
pkg set, method (UintptrT) Union(map[uintptr]struct{}, map[uintptr]struct{})
161+
pkg set, type Complex128BoolT struct
162+
pkg set, type Complex128T struct
163+
pkg set, type Complex64BoolT struct
164+
pkg set, type Complex64T struct
165+
pkg set, type Float32BoolT struct
166+
pkg set, type Float32T struct
167+
pkg set, type Float64BoolT struct
168+
pkg set, type Float64T struct
169+
pkg set, type Int16BoolT struct
170+
pkg set, type Int16T struct
171+
pkg set, type Int32BoolT struct
172+
pkg set, type Int32T struct
173+
pkg set, type Int64BoolT struct
174+
pkg set, type Int64T struct
175+
pkg set, type Int8BoolT struct
176+
pkg set, type Int8T struct
177+
pkg set, type IntBoolT struct
178+
pkg set, type IntT struct
179+
pkg set, type StringBoolT struct
180+
pkg set, type StringT struct
181+
pkg set, type Uint16BoolT struct
182+
pkg set, type Uint16T struct
183+
pkg set, type Uint32BoolT struct
184+
pkg set, type Uint32T struct
185+
pkg set, type Uint64BoolT struct
186+
pkg set, type Uint64T struct
187+
pkg set, type Uint8BoolT struct
188+
pkg set, type Uint8T struct
189+
pkg set, type UintBoolT struct
190+
pkg set, type UintT struct
191+
pkg set, type UintptrBoolT struct
192+
pkg set, type UintptrT struct
193+
pkg set, var Complex128 Complex128T
194+
pkg set, var Complex128Bool Complex128BoolT
195+
pkg set, var Complex64 Complex64T
196+
pkg set, var Complex64Bool Complex64BoolT
197+
pkg set, var Float32 Float32T
198+
pkg set, var Float32Bool Float32BoolT
199+
pkg set, var Float64 Float64T
200+
pkg set, var Float64Bool Float64BoolT
201+
pkg set, var Int IntT
202+
pkg set, var Int16 Int16T
203+
pkg set, var Int16Bool Int16BoolT
204+
pkg set, var Int32 Int32T
205+
pkg set, var Int32Bool Int32BoolT
206+
pkg set, var Int64 Int64T
207+
pkg set, var Int64Bool Int64BoolT
208+
pkg set, var Int8 Int8T
209+
pkg set, var Int8Bool Int8BoolT
210+
pkg set, var IntBool IntBoolT
211+
pkg set, var String StringT
212+
pkg set, var StringBool StringBoolT
213+
pkg set, var Uint UintT
214+
pkg set, var Uint16 Uint16T
215+
pkg set, var Uint16Bool Uint16BoolT
216+
pkg set, var Uint32 Uint32T
217+
pkg set, var Uint32Bool Uint32BoolT
218+
pkg set, var Uint64 Uint64T
219+
pkg set, var Uint64Bool Uint64BoolT
220+
pkg set, var Uint8 Uint8T
221+
pkg set, var Uint8Bool Uint8BoolT
222+
pkg set, var UintBool UintBoolT
223+
pkg set, var Uintptr UintptrT
224+
pkg set, var UintptrBool UintptrBoolT

set/complex128.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2015 The Vanadium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// This file was auto-generated via go generate.
6+
// DO NOT UPDATE MANUALLY
7+
8+
package set
9+
10+
var Complex128 = Complex128T{}
11+
12+
type Complex128T struct{}
13+
14+
// FromSlice transforms the given slice to a set.
15+
func (Complex128T) FromSlice(els []complex128) map[complex128]struct{} {
16+
if len(els) == 0 {
17+
return nil
18+
}
19+
result := map[complex128]struct{}{}
20+
for _, el := range els {
21+
result[el] = struct{}{}
22+
}
23+
return result
24+
}
25+
26+
// ToSlice transforms the given set to a slice.
27+
func (Complex128T) ToSlice(s map[complex128]struct{}) []complex128 {
28+
var result []complex128
29+
for el, _ := range s {
30+
result = append(result, el)
31+
}
32+
return result
33+
}
34+
35+
// Difference subtracts s2 from s1, storing the result in s1.
36+
func (Complex128T) Difference(s1, s2 map[complex128]struct{}) {
37+
for el, _ := range s1 {
38+
if _, ok := s2[el]; ok {
39+
delete(s1, el)
40+
}
41+
}
42+
}
43+
44+
// Intersection intersects s1 and s2, storing the result in s1.
45+
func (Complex128T) Intersection(s1, s2 map[complex128]struct{}) {
46+
for el, _ := range s1 {
47+
if _, ok := s2[el]; !ok {
48+
delete(s1, el)
49+
}
50+
}
51+
}
52+
53+
// Union merges s1 and s2, storing the result in s1.
54+
func (Complex128T) Union(s1, s2 map[complex128]struct{}) {
55+
for el, _ := range s2 {
56+
s1[el] = struct{}{}
57+
}
58+
}

0 commit comments

Comments
 (0)