github.com/bytedance/gopkg@v0.0.0-20240514070511-01b2cbcf35e1/collection/hashset/types.go (about) 1 // Copyright 2021 ByteDance Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by go run types_gen.go; DO NOT EDIT. 16 17 package hashset 18 19 type Float32Set map[float32]struct{} 20 21 // NewFloat32 returns an empty float32 set 22 func NewFloat32() Float32Set { 23 return make(map[float32]struct{}) 24 } 25 26 // NewFloat32WithSize returns an empty float32 set initialized with specific size 27 func NewFloat32WithSize(size int) Float32Set { 28 return make(map[float32]struct{}, size) 29 } 30 31 // Add adds the specified element to this set 32 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 33 // Reserves the return type for future extension 34 func (s Float32Set) Add(value float32) bool { 35 s[value] = struct{}{} 36 return true 37 } 38 39 // Contains returns true if this set contains the specified element 40 func (s Float32Set) Contains(value float32) bool { 41 if _, ok := s[value]; ok { 42 return true 43 } 44 return false 45 } 46 47 // Remove removes the specified element from this set 48 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 49 // Reserves the return type for future extension 50 func (s Float32Set) Remove(value float32) bool { 51 delete(s, value) 52 return true 53 } 54 55 // Range calls f sequentially for each value present in the hashset. 56 // If f returns false, range stops the iteration. 57 func (s Float32Set) Range(f func(value float32) bool) { 58 for k := range s { 59 if !f(k) { 60 break 61 } 62 } 63 } 64 65 // Len returns the number of elements of this set 66 67 func (s Float32Set) Len() int { 68 return len(s) 69 } 70 71 type Float64Set map[float64]struct{} 72 73 // NewFloat64 returns an empty float64 set 74 func NewFloat64() Float64Set { 75 return make(map[float64]struct{}) 76 } 77 78 // NewFloat64WithSize returns an empty float64 set initialized with specific size 79 func NewFloat64WithSize(size int) Float64Set { 80 return make(map[float64]struct{}, size) 81 } 82 83 // Add adds the specified element to this set 84 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 85 // Reserves the return type for future extension 86 func (s Float64Set) Add(value float64) bool { 87 s[value] = struct{}{} 88 return true 89 } 90 91 // Contains returns true if this set contains the specified element 92 func (s Float64Set) Contains(value float64) bool { 93 if _, ok := s[value]; ok { 94 return true 95 } 96 return false 97 } 98 99 // Remove removes the specified element from this set 100 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 101 // Reserves the return type for future extension 102 func (s Float64Set) Remove(value float64) bool { 103 delete(s, value) 104 return true 105 } 106 107 // Range calls f sequentially for each value present in the hashset. 108 // If f returns false, range stops the iteration. 109 func (s Float64Set) Range(f func(value float64) bool) { 110 for k := range s { 111 if !f(k) { 112 break 113 } 114 } 115 } 116 117 // Len returns the number of elements of this set 118 119 func (s Float64Set) Len() int { 120 return len(s) 121 } 122 123 type Int32Set map[int32]struct{} 124 125 // NewInt32 returns an empty int32 set 126 func NewInt32() Int32Set { 127 return make(map[int32]struct{}) 128 } 129 130 // NewInt32WithSize returns an empty int32 set initialized with specific size 131 func NewInt32WithSize(size int) Int32Set { 132 return make(map[int32]struct{}, size) 133 } 134 135 // Add adds the specified element to this set 136 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 137 // Reserves the return type for future extension 138 func (s Int32Set) Add(value int32) bool { 139 s[value] = struct{}{} 140 return true 141 } 142 143 // Contains returns true if this set contains the specified element 144 func (s Int32Set) Contains(value int32) bool { 145 if _, ok := s[value]; ok { 146 return true 147 } 148 return false 149 } 150 151 // Remove removes the specified element from this set 152 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 153 // Reserves the return type for future extension 154 func (s Int32Set) Remove(value int32) bool { 155 delete(s, value) 156 return true 157 } 158 159 // Range calls f sequentially for each value present in the hashset. 160 // If f returns false, range stops the iteration. 161 func (s Int32Set) Range(f func(value int32) bool) { 162 for k := range s { 163 if !f(k) { 164 break 165 } 166 } 167 } 168 169 // Len returns the number of elements of this set 170 171 func (s Int32Set) Len() int { 172 return len(s) 173 } 174 175 type Int16Set map[int16]struct{} 176 177 // NewInt16 returns an empty int16 set 178 func NewInt16() Int16Set { 179 return make(map[int16]struct{}) 180 } 181 182 // NewInt16WithSize returns an empty int16 set initialized with specific size 183 func NewInt16WithSize(size int) Int16Set { 184 return make(map[int16]struct{}, size) 185 } 186 187 // Add adds the specified element to this set 188 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 189 // Reserves the return type for future extension 190 func (s Int16Set) Add(value int16) bool { 191 s[value] = struct{}{} 192 return true 193 } 194 195 // Contains returns true if this set contains the specified element 196 func (s Int16Set) Contains(value int16) bool { 197 if _, ok := s[value]; ok { 198 return true 199 } 200 return false 201 } 202 203 // Remove removes the specified element from this set 204 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 205 // Reserves the return type for future extension 206 func (s Int16Set) Remove(value int16) bool { 207 delete(s, value) 208 return true 209 } 210 211 // Range calls f sequentially for each value present in the hashset. 212 // If f returns false, range stops the iteration. 213 func (s Int16Set) Range(f func(value int16) bool) { 214 for k := range s { 215 if !f(k) { 216 break 217 } 218 } 219 } 220 221 // Len returns the number of elements of this set 222 223 func (s Int16Set) Len() int { 224 return len(s) 225 } 226 227 type IntSet map[int]struct{} 228 229 // NewInt returns an empty int set 230 func NewInt() IntSet { 231 return make(map[int]struct{}) 232 } 233 234 // NewIntWithSize returns an empty int set initialized with specific size 235 func NewIntWithSize(size int) IntSet { 236 return make(map[int]struct{}, size) 237 } 238 239 // Add adds the specified element to this set 240 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 241 // Reserves the return type for future extension 242 func (s IntSet) Add(value int) bool { 243 s[value] = struct{}{} 244 return true 245 } 246 247 // Contains returns true if this set contains the specified element 248 func (s IntSet) Contains(value int) bool { 249 if _, ok := s[value]; ok { 250 return true 251 } 252 return false 253 } 254 255 // Remove removes the specified element from this set 256 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 257 // Reserves the return type for future extension 258 func (s IntSet) Remove(value int) bool { 259 delete(s, value) 260 return true 261 } 262 263 // Range calls f sequentially for each value present in the hashset. 264 // If f returns false, range stops the iteration. 265 func (s IntSet) Range(f func(value int) bool) { 266 for k := range s { 267 if !f(k) { 268 break 269 } 270 } 271 } 272 273 // Len returns the number of elements of this set 274 275 func (s IntSet) Len() int { 276 return len(s) 277 } 278 279 type Uint64Set map[uint64]struct{} 280 281 // NewUint64 returns an empty uint64 set 282 func NewUint64() Uint64Set { 283 return make(map[uint64]struct{}) 284 } 285 286 // NewUint64WithSize returns an empty uint64 set initialized with specific size 287 func NewUint64WithSize(size int) Uint64Set { 288 return make(map[uint64]struct{}, size) 289 } 290 291 // Add adds the specified element to this set 292 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 293 // Reserves the return type for future extension 294 func (s Uint64Set) Add(value uint64) bool { 295 s[value] = struct{}{} 296 return true 297 } 298 299 // Contains returns true if this set contains the specified element 300 func (s Uint64Set) Contains(value uint64) bool { 301 if _, ok := s[value]; ok { 302 return true 303 } 304 return false 305 } 306 307 // Remove removes the specified element from this set 308 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 309 // Reserves the return type for future extension 310 func (s Uint64Set) Remove(value uint64) bool { 311 delete(s, value) 312 return true 313 } 314 315 // Range calls f sequentially for each value present in the hashset. 316 // If f returns false, range stops the iteration. 317 func (s Uint64Set) Range(f func(value uint64) bool) { 318 for k := range s { 319 if !f(k) { 320 break 321 } 322 } 323 } 324 325 // Len returns the number of elements of this set 326 327 func (s Uint64Set) Len() int { 328 return len(s) 329 } 330 331 type Uint32Set map[uint32]struct{} 332 333 // NewUint32 returns an empty uint32 set 334 func NewUint32() Uint32Set { 335 return make(map[uint32]struct{}) 336 } 337 338 // NewUint32WithSize returns an empty uint32 set initialized with specific size 339 func NewUint32WithSize(size int) Uint32Set { 340 return make(map[uint32]struct{}, size) 341 } 342 343 // Add adds the specified element to this set 344 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 345 // Reserves the return type for future extension 346 func (s Uint32Set) Add(value uint32) bool { 347 s[value] = struct{}{} 348 return true 349 } 350 351 // Contains returns true if this set contains the specified element 352 func (s Uint32Set) Contains(value uint32) bool { 353 if _, ok := s[value]; ok { 354 return true 355 } 356 return false 357 } 358 359 // Remove removes the specified element from this set 360 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 361 // Reserves the return type for future extension 362 func (s Uint32Set) Remove(value uint32) bool { 363 delete(s, value) 364 return true 365 } 366 367 // Range calls f sequentially for each value present in the hashset. 368 // If f returns false, range stops the iteration. 369 func (s Uint32Set) Range(f func(value uint32) bool) { 370 for k := range s { 371 if !f(k) { 372 break 373 } 374 } 375 } 376 377 // Len returns the number of elements of this set 378 379 func (s Uint32Set) Len() int { 380 return len(s) 381 } 382 383 type Uint16Set map[uint16]struct{} 384 385 // NewUint16 returns an empty uint16 set 386 func NewUint16() Uint16Set { 387 return make(map[uint16]struct{}) 388 } 389 390 // NewUint16WithSize returns an empty uint16 set initialized with specific size 391 func NewUint16WithSize(size int) Uint16Set { 392 return make(map[uint16]struct{}, size) 393 } 394 395 // Add adds the specified element to this set 396 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 397 // Reserves the return type for future extension 398 func (s Uint16Set) Add(value uint16) bool { 399 s[value] = struct{}{} 400 return true 401 } 402 403 // Contains returns true if this set contains the specified element 404 func (s Uint16Set) Contains(value uint16) bool { 405 if _, ok := s[value]; ok { 406 return true 407 } 408 return false 409 } 410 411 // Remove removes the specified element from this set 412 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 413 // Reserves the return type for future extension 414 func (s Uint16Set) Remove(value uint16) bool { 415 delete(s, value) 416 return true 417 } 418 419 // Range calls f sequentially for each value present in the hashset. 420 // If f returns false, range stops the iteration. 421 func (s Uint16Set) Range(f func(value uint16) bool) { 422 for k := range s { 423 if !f(k) { 424 break 425 } 426 } 427 } 428 429 // Len returns the number of elements of this set 430 431 func (s Uint16Set) Len() int { 432 return len(s) 433 } 434 435 type UintSet map[uint]struct{} 436 437 // NewUint returns an empty uint set 438 func NewUint() UintSet { 439 return make(map[uint]struct{}) 440 } 441 442 // NewUintWithSize returns an empty uint set initialized with specific size 443 func NewUintWithSize(size int) UintSet { 444 return make(map[uint]struct{}, size) 445 } 446 447 // Add adds the specified element to this set 448 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 449 // Reserves the return type for future extension 450 func (s UintSet) Add(value uint) bool { 451 s[value] = struct{}{} 452 return true 453 } 454 455 // Contains returns true if this set contains the specified element 456 func (s UintSet) Contains(value uint) bool { 457 if _, ok := s[value]; ok { 458 return true 459 } 460 return false 461 } 462 463 // Remove removes the specified element from this set 464 // Always returns true due to the build-in map doesn't indicate caller whether the given element already exists 465 // Reserves the return type for future extension 466 func (s UintSet) Remove(value uint) bool { 467 delete(s, value) 468 return true 469 } 470 471 // Range calls f sequentially for each value present in the hashset. 472 // If f returns false, range stops the iteration. 473 func (s UintSet) Range(f func(value uint) bool) { 474 for k := range s { 475 if !f(k) { 476 break 477 } 478 } 479 } 480 481 // Len returns the number of elements of this set 482 483 func (s UintSet) Len() int { 484 return len(s) 485 }