Skip to content

Commit

Permalink
Revert uniq to main
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Jan 3, 2024
1 parent e077d31 commit 6d1f36b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions attribute/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,23 @@ func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (S

*tmp = nil

// Use filteredToFront here for last-value-wins semantics.
prev := kvs[n-1].Key
uniq := filteredToFront(kvs[:n-1], func(kv KeyValue) bool {
if kv.Key == prev {
return false
position := len(kvs) - 1
offset := position - 1

// The requirements stated above require that the stable
// result be placed in the end of the input slice, while
// overwritten values are swapped to the beginning.
//
// De-duplicate with last-value-wins semantics. Preserve
// duplicate values at the beginning of the input slice.
for ; offset >= 0; offset-- {
if kvs[offset].Key == kvs[position].Key {
continue
}
prev = kv.Key
return true
})
kvs = kvs[uniq:]
position--
kvs[offset], kvs[position] = kvs[position], kvs[offset]
}
kvs = kvs[position:]

if filter != nil {
// TODO (MrAlias): there is a potential optimization here where the
Expand Down

0 comments on commit 6d1f36b

Please sign in to comment.