@@ -19,6 +19,21 @@ func InInt64s(s []int64, v int64) bool {
19
19
return ContainsInt64 (s , v )
20
20
}
21
21
22
+ // InUInts is an alias of ContainsUInt, returns true if an uint is present in a iteratee.
23
+ func InUInts (s []uint , v uint ) bool {
24
+ return ContainsUInt (s , v )
25
+ }
26
+
27
+ // InUInt32s is an alias of ContainsUInt32, returns true if an uint32 is present in a iteratee.
28
+ func InUInt32s (s []uint32 , v uint32 ) bool {
29
+ return ContainsUInt32 (s , v )
30
+ }
31
+
32
+ // InUInt64s is an alias of ContainsUInt64, returns true if an uint64 is present in a iteratee.
33
+ func InUInt64s (s []uint64 , v uint64 ) bool {
34
+ return ContainsUInt64 (s , v )
35
+ }
36
+
22
37
// InStrings is an alias of ContainsString, returns true if a string is present in a iteratee.
23
38
func InStrings (s []string , v string ) bool {
24
39
return ContainsString (s , v )
@@ -198,6 +213,54 @@ func FilterInt64(s []int64, cb func(s int64) bool) []int64 {
198
213
return results
199
214
}
200
215
216
+ // FilterUInt iterates over a collection of uint, returning an array of
217
+ // all uint elements predicate returns truthy for.
218
+ func FilterUInt (s []uint , cb func (s uint ) bool ) []uint {
219
+ results := []uint {}
220
+
221
+ for _ , i := range s {
222
+ result := cb (i )
223
+
224
+ if result {
225
+ results = append (results , i )
226
+ }
227
+ }
228
+
229
+ return results
230
+ }
231
+
232
+ // FilterUInt32 iterates over a collection of uint32, returning an array of
233
+ // all uint32 elements predicate returns truthy for.
234
+ func FilterUInt32 (s []uint32 , cb func (s uint32 ) bool ) []uint32 {
235
+ results := []uint32 {}
236
+
237
+ for _ , i := range s {
238
+ result := cb (i )
239
+
240
+ if result {
241
+ results = append (results , i )
242
+ }
243
+ }
244
+
245
+ return results
246
+ }
247
+
248
+ // FilterUInt64 iterates over a collection of uint64, returning an array of
249
+ // all uint64 elements predicate returns truthy for.
250
+ func FilterUInt64 (s []uint64 , cb func (s uint64 ) bool ) []uint64 {
251
+ results := []uint64 {}
252
+
253
+ for _ , i := range s {
254
+ result := cb (i )
255
+
256
+ if result {
257
+ results = append (results , i )
258
+ }
259
+ }
260
+
261
+ return results
262
+ }
263
+
201
264
// FilterString iterates over a collection of string, returning an array of
202
265
// all string elements predicate returns truthy for.
203
266
func FilterString (s []string , cb func (s string ) bool ) []string {
@@ -244,6 +307,37 @@ func ContainsInt64(s []int64, v int64) bool {
244
307
return false
245
308
}
246
309
310
+ // ContainsUInt returns true if an uint is present in a iteratee.
311
+ func ContainsUInt (s []uint , v uint ) bool {
312
+ for _ , vv := range s {
313
+ if vv == v {
314
+ return true
315
+ }
316
+ }
317
+ return false
318
+ }
319
+
320
+ // ContainsUInt32 returns true if an uint32 is present in a iteratee.
321
+ func ContainsUInt32 (s []uint32 , v uint32 ) bool {
322
+ for _ , vv := range s {
323
+ if vv == v {
324
+ return true
325
+ }
326
+ }
327
+ return false
328
+ }
329
+
330
+ // ContainsUInt64 returns true if an uint64 is present in a iteratee.
331
+ func ContainsUInt64 (s []uint64 , v uint64 ) bool {
332
+ for _ , vv := range s {
333
+ if vv == v {
334
+ return true
335
+ }
336
+ }
337
+ return false
338
+ }
339
+
340
+
247
341
// ContainsString returns true if a string is present in a iteratee.
248
342
func ContainsString (s []string , v string ) bool {
249
343
for _ , vv := range s {
@@ -298,6 +392,30 @@ func SumInt(s []int) (sum int) {
298
392
return
299
393
}
300
394
395
+ // SumUInt32 sums a uint32 iteratee and returns the sum of all elements
396
+ func SumUInt32 (s []uint32 ) (sum uint32 ) {
397
+ for _ , v := range s {
398
+ sum += v
399
+ }
400
+ return
401
+ }
402
+
403
+ // SumUInt64 sums a uint64 iteratee and returns the sum of all elements
404
+ func SumUInt64 (s []uint64 ) (sum uint64 ) {
405
+ for _ , v := range s {
406
+ sum += v
407
+ }
408
+ return
409
+ }
410
+
411
+ // SumUInt sums a uint iteratee and returns the sum of all elements
412
+ func SumUInt (s []uint ) (sum uint ) {
413
+ for _ , v := range s {
414
+ sum += v
415
+ }
416
+ return
417
+ }
418
+
301
419
// SumFloat64 sums a float64 iteratee and returns the sum of all elements
302
420
func SumFloat64 (s []float64 ) (sum float64 ) {
303
421
for _ , v := range s {
@@ -346,6 +464,30 @@ func ReverseInt64(s []int64) []int64 {
346
464
return s
347
465
}
348
466
467
+ // ReverseUInt reverses an array of int
468
+ func ReverseUInt (s []uint ) []uint {
469
+ for i , j := 0 , len (s )- 1 ; i < len (s )/ 2 ; i , j = i + 1 , j - 1 {
470
+ s [i ], s [j ] = s [j ], s [i ]
471
+ }
472
+ return s
473
+ }
474
+
475
+ // ReverseUInt32 reverses an array of uint32
476
+ func ReverseUInt32 (s []uint32 ) []uint32 {
477
+ for i , j := 0 , len (s )- 1 ; i < len (s )/ 2 ; i , j = i + 1 , j - 1 {
478
+ s [i ], s [j ] = s [j ], s [i ]
479
+ }
480
+ return s
481
+ }
482
+
483
+ // ReverseUInt64 reverses an array of uint64
484
+ func ReverseUInt64 (s []uint64 ) []uint64 {
485
+ for i , j := 0 , len (s )- 1 ; i < len (s )/ 2 ; i , j = i + 1 , j - 1 {
486
+ s [i ], s [j ] = s [j ], s [i ]
487
+ }
488
+ return s
489
+ }
490
+
349
491
// ReverseFloat64 reverses an array of float64
350
492
func ReverseFloat64 (s []float64 ) []float64 {
351
493
for i , j := 0 , len (s )- 1 ; i < len (s )/ 2 ; i , j = i + 1 , j - 1 {
@@ -398,6 +540,24 @@ func IndexOfInt64(a []int64, x int64) int {
398
540
return indexOf (len (a ), func (i int ) bool { return a [i ] == x })
399
541
}
400
542
543
+ // IndexOfUInt gets the index at which the first occurrence of an uint value is found in array or return -1
544
+ // if the value cannot be found
545
+ func IndexOfUInt (a []uint , x uint ) int {
546
+ return indexOf (len (a ), func (i int ) bool { return a [i ] == x })
547
+ }
548
+
549
+ // IndexOfUInt32 gets the index at which the first occurrence of an uint32 value is found in array or return -1
550
+ // if the value cannot be found
551
+ func IndexOfUInt32 (a []uint32 , x uint32 ) int {
552
+ return indexOf (len (a ), func (i int ) bool { return a [i ] == x })
553
+ }
554
+
555
+ // IndexOfUInt64 gets the index at which the first occurrence of an uint64 value is found in array or return -1
556
+ // if the value cannot be found
557
+ func IndexOfUInt64 (a []uint64 , x uint64 ) int {
558
+ return indexOf (len (a ), func (i int ) bool { return a [i ] == x })
559
+ }
560
+
401
561
// IndexOfFloat64 gets the index at which the first occurrence of an float64 value is found in array or return -1
402
562
// if the value cannot be found
403
563
func IndexOfFloat64 (a []float64 , x float64 ) int {
@@ -437,6 +597,24 @@ func LastIndexOfInt64(a []int64, x int64) int {
437
597
return lastIndexOf (len (a ), func (i int ) bool { return a [i ] == x })
438
598
}
439
599
600
+ // LastIndexOfUInt gets the index at which the first occurrence of an uint value is found in array or return -1
601
+ // if the value cannot be found
602
+ func LastIndexOfUInt (a []uint , x uint ) int {
603
+ return lastIndexOf (len (a ), func (i int ) bool { return a [i ] == x })
604
+ }
605
+
606
+ // LastIndexOfUInt32 gets the index at which the first occurrence of an uint32 value is found in array or return -1
607
+ // if the value cannot be found
608
+ func LastIndexOfUInt32 (a []uint32 , x uint32 ) int {
609
+ return lastIndexOf (len (a ), func (i int ) bool { return a [i ] == x })
610
+ }
611
+
612
+ // LastIndexOfUInt64 gets the index at which the first occurrence of an uint64 value is found in array or return -1
613
+ // if the value cannot be found
614
+ func LastIndexOfUInt64 (a []uint64 , x uint64 ) int {
615
+ return lastIndexOf (len (a ), func (i int ) bool { return a [i ] == x })
616
+ }
617
+
440
618
// LastIndexOfFloat64 gets the index at which the first occurrence of an float64 value is found in array or return -1
441
619
// if the value cannot be found
442
620
func LastIndexOfFloat64 (a []float64 , x float64 ) int {
@@ -521,6 +699,72 @@ func UniqInt(a []int) []int {
521
699
return a [0 :j ]
522
700
}
523
701
702
+ // UniqUInt32 creates an array of uint32 with unique values.
703
+ func UniqUInt32 (a []uint32 ) []uint32 {
704
+ length := len (a )
705
+
706
+ seen := make (map [uint32 ]struct {}, length )
707
+ j := 0
708
+
709
+ for i := 0 ; i < length ; i ++ {
710
+ v := a [i ]
711
+
712
+ if _ , ok := seen [v ]; ok {
713
+ continue
714
+ }
715
+
716
+ seen [v ] = struct {}{}
717
+ a [j ] = v
718
+ j ++
719
+ }
720
+
721
+ return a [0 :j ]
722
+ }
723
+
724
+ // UniqUInt64 creates an array of uint64 with unique values.
725
+ func UniqUInt64 (a []uint64 ) []uint64 {
726
+ length := len (a )
727
+
728
+ seen := make (map [uint64 ]struct {}, length )
729
+ j := 0
730
+
731
+ for i := 0 ; i < length ; i ++ {
732
+ v := a [i ]
733
+
734
+ if _ , ok := seen [v ]; ok {
735
+ continue
736
+ }
737
+
738
+ seen [v ] = struct {}{}
739
+ a [j ] = v
740
+ j ++
741
+ }
742
+
743
+ return a [0 :j ]
744
+ }
745
+
746
+ // UniqUInt creates an array of uint with unique values.
747
+ func UniqUInt (a []uint ) []uint {
748
+ length := len (a )
749
+
750
+ seen := make (map [uint ]struct {}, length )
751
+ j := 0
752
+
753
+ for i := 0 ; i < length ; i ++ {
754
+ v := a [i ]
755
+
756
+ if _ , ok := seen [v ]; ok {
757
+ continue
758
+ }
759
+
760
+ seen [v ] = struct {}{}
761
+ a [j ] = v
762
+ j ++
763
+ }
764
+
765
+ return a [0 :j ]
766
+ }
767
+
524
768
// UniqString creates an array of string with unique values.
525
769
func UniqString (a []string ) []string {
526
770
length := len (a )
@@ -617,6 +861,36 @@ func ShuffleInt64(a []int64) []int64 {
617
861
return a
618
862
}
619
863
864
+ // ShuffleUInt creates an array of int shuffled values using Fisher–Yates algorithm
865
+ func ShuffleUInt (a []uint ) []uint {
866
+ for i := range a {
867
+ j := rand .Intn (i + 1 )
868
+ a [i ], a [j ] = a [j ], a [i ]
869
+ }
870
+
871
+ return a
872
+ }
873
+
874
+ // ShuffleUInt32 creates an array of uint32 shuffled values using Fisher–Yates algorithm
875
+ func ShuffleUInt32 (a []uint32 ) []uint32 {
876
+ for i := range a {
877
+ j := rand .Intn (i + 1 )
878
+ a [i ], a [j ] = a [j ], a [i ]
879
+ }
880
+
881
+ return a
882
+ }
883
+
884
+ // ShuffleUInt64 creates an array of uint64 shuffled values using Fisher–Yates algorithm
885
+ func ShuffleUInt64 (a []uint64 ) []uint64 {
886
+ for i := range a {
887
+ j := rand .Intn (i + 1 )
888
+ a [i ], a [j ] = a [j ], a [i ]
889
+ }
890
+
891
+ return a
892
+ }
893
+
620
894
// ShuffleString creates an array of string shuffled values using Fisher–Yates algorithm
621
895
func ShuffleString (a []string ) []string {
622
896
for i := range a {
@@ -667,6 +941,21 @@ func DropInt64(s []int64, n int) []int64 {
667
941
return s [n :]
668
942
}
669
943
944
+ // DropUInt creates a slice with `n` ints dropped from the beginning.
945
+ func DropUInt (s []uint , n uint ) []uint {
946
+ return s [n :]
947
+ }
948
+
949
+ // DropUInt32 creates a slice with `n` int32s dropped from the beginning.
950
+ func DropUInt32 (s []uint32 , n int ) []uint32 {
951
+ return s [n :]
952
+ }
953
+
954
+ // DropUInt64 creates a slice with `n` int64s dropped from the beginning.
955
+ func DropUInt64 (s []uint64 , n int ) []uint64 {
956
+ return s [n :]
957
+ }
958
+
670
959
// DropFloat32 creates a slice with `n` float32s dropped from the beginning.
671
960
func DropFloat32 (s []float32 , n int ) []float32 {
672
961
return s [n :]
0 commit comments