1
0
Fork 0
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:
mcrakhman 2024-11-20 14:52:33 +01:00
parent 0cf4118ba6
commit 04e993ec6a
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
6 changed files with 107 additions and 63 deletions

View file

@ -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