mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-09 09:35:03 +09:00
History tree with tree builder
This commit is contained in:
parent
0cf4118ba6
commit
04e993ec6a
6 changed files with 107 additions and 63 deletions
|
@ -145,6 +145,28 @@ func ContainsSorted[T constraints.Ordered](seq []T, subseq []T) bool {
|
|||
return j == len(subseq)
|
||||
}
|
||||
|
||||
func DiscardDuplicatesSorted[T comparable](sorted []T) []T {
|
||||
cnt := 0
|
||||
for i := 0; i < len(sorted)-1; i++ {
|
||||
if sorted[i] != sorted[i+1] {
|
||||
cnt++
|
||||
sorted[cnt] = sorted[i+1]
|
||||
}
|
||||
}
|
||||
return sorted[:cnt+1]
|
||||
}
|
||||
|
||||
func DiscardDuplicatesSortedFunc[T any](sorted []T, equal func(T, T) bool) []T {
|
||||
cnt := 0
|
||||
for i := 0; i < len(sorted)-1; i++ {
|
||||
if !equal(sorted[i], sorted[i+1]) {
|
||||
cnt++
|
||||
sorted[cnt] = sorted[i+1]
|
||||
}
|
||||
}
|
||||
return sorted[:cnt+1]
|
||||
}
|
||||
|
||||
func DiscardFromSlice[T any](elements []T, isDiscarded func(T) bool) []T {
|
||||
var (
|
||||
finishedIdx = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue