MCPcopy Create free account
hub / github.com/benbjohnson/immutable / validateBackwardIterator

Method validateBackwardIterator

immutable_test.go:2294–2312  ·  view source on GitHub ↗
(itr *SortedMapIterator[int, int])

Source from the content-addressed store, hash-verified

2292}
2293
2294func (m *TSortedMap) validateBackwardIterator(itr *SortedMapIterator[int, int]) error {
2295 itr.Last()
2296 for i := len(m.keys) - 1; i >= 0; i-- {
2297 k0 := m.keys[i]
2298 v0 := m.std[k0]
2299 if k1, v1, ok := itr.Prev(); !ok || k0 != k1 || v0 != v1 {
2300 return fmt.Errorf("%d. SortedMapIterator.Prev()=<%v,%v>, expected <%v,%v>", i, k1, v1, k0, v0)
2301 }
2302
2303 done := i == 0
2304 if v := itr.Done(); v != done {
2305 return fmt.Errorf("%d. SortedMapIterator.Done()=%v, expected %v", i, v, done)
2306 }
2307 }
2308 if k, v, ok := itr.Prev(); ok {
2309 return fmt.Errorf("SortedMapIterator.Prev()=<%v,%v>, expected nil after done", k, v)
2310 }
2311 return nil
2312}
2313
2314func BenchmarkSortedMap_Set(b *testing.B) {
2315 b.ReportAllocs()

Callers 1

ValidateMethod · 0.95

Calls 3

LastMethod · 0.45
PrevMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected