# Nim-LibP2P # Copyright (c) 2023 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) # at your option. # This file may not be copied, modified, or distributed except according to # those terms. import sequtils type OffsettedSeq*[T] = object s*: seq[T] offset*: int proc initOffsettedSeq*[T](offset: int = 0): OffsettedSeq[T] = OffsettedSeq[T](s: newSeq[T](), offset: offset) proc all*[T](o: OffsettedSeq[T], pred: proc (x: T): bool): bool = o.s.all(pred) proc any*[T](o: OffsettedSeq[T], pred: proc (x: T): bool): bool = o.s.any(pred) proc apply*[T](o: OffsettedSeq[T], op: proc (x: T)) = o.s.apply(pred) proc apply*[T](o: OffsettedSeq[T], op: proc (x: T): T) = o.s.apply(pred) proc apply*[T](o: OffsettedSeq[T], op: proc (x: var T)) = o.s.apply(pred) func count*[T](o: OffsettedSeq[T], x: T): int = o.s.count(x) proc flushIf*[T](o: OffsettedSeq[T], pred: proc (x: T): bool) = var i = 0 for e in o.s: if not pred(e): break i.inc() if i > 0: o.s.delete(0.. 0: o.s.delete(0..