Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 3 of 3 for FilterDuplicatesPresorted (0.43 sec)

  1. pkg/util/smallset/smallset.go

    // Duplicates are removed
    func New[T constraints.Ordered](items ...T) Set[T] {
    	if len(items) == 1 {
    		return Set[T]{items: items}
    	}
    	slices.Sort(items)
    	items = slices.FilterDuplicatesPresorted(items)
    	return Set[T]{items: items}
    }
    
    // CopyAndInsert builds a *new* with all the current items plus new items
    func (s Set[T]) CopyAndInsert(items ...T) Set[T] {
    	slices.Sort(items)
    Registered: Fri Jun 14 15:00:06 UTC 2024
    - Last Modified: Fri May 10 23:33:56 UTC 2024
    - 3.2K bytes
    - Viewed (0)
  2. pkg/slices/slices.go

    	var empty E
    	for i := n; i < len(s); i++ {
    		s[i] = empty
    	}
    
    	s = s[:n]
    	return s
    }
    
    // FilterDuplicatesPresorted retains all unique elements in []E.
    // The slices MUST be pre-sorted.
    func FilterDuplicatesPresorted[E comparable](s []E) []E {
    	if len(s) <= 1 {
    		return s
    	}
    	n := 1
    	for i := 1; i < len(s); i++ {
    		val := s[i]
    		if val != s[i-1] {
    Registered: Fri Jun 14 15:00:06 UTC 2024
    - Last Modified: Wed May 15 06:28:11 UTC 2024
    - 7.9K bytes
    - Viewed (0)
  3. pkg/slices/slices_test.go

    		},
    		{
    			name: "dupes middle",
    			in:   []string{"a", "b", "b", "c"},
    			out:  []string{"a", "b", "c"},
    		},
    	}
    	for _, tt := range tests {
    		t.Run(tt.name, func(t *testing.T) {
    			got := FilterDuplicatesPresorted(tt.in)
    			assert.Equal(t, tt.out, got)
    			assert.Equal(t, tt.out, tt.in[:len(tt.out)])
    		})
    	}
    Registered: Fri Jun 14 15:00:06 UTC 2024
    - Last Modified: Fri May 10 23:33:56 UTC 2024
    - 18.2K bytes
    - Viewed (0)
Back to top