콘텐츠로 이동
Bluetape4k 문서1.11

Bounded collections

최신 안정판 Bluetape4k 1.11.0 릴리스 기준

BoundedStackRingBuffer는 모두 가장 오래된 값을 제거해 memory를 제한하지만 읽는 순서가 반대입니다.

Capacity 3에서 BoundedStack과 RingBuffer의 ordering 비교

요구타입index 0iteration
최근 값부터 읽기, undo/history stackBoundedStacknewest/topnewest → oldest
시간 순서로 recent history 순회RingBufferoldest/read headoldest → newest

둘 다 maxSize > 0을 생성 시 검증하고 ReentrantLock으로 public read/write를 보호합니다.

val stack = BoundedStack<Int>(3).apply { pushAll(1, 2, 3, 4) }
val ring = RingBuffer<Int>(3).apply { addAll(1, 2, 3, 4) }
check(stack.toList() == listOf(4, 3, 2))
check(ring.toList() == listOf(2, 3, 4))

두 collection 모두 1을 evict합니다. BoundedStack.pop()은 4부터 제거하고, RingBuffer.drop(1)은 2부터 제거합니다.

BoundedStackpush, pop, peek, insert, update, remove를 stack top 기준 index로 제공합니다. Empty pop/peekNoSuchElementException, 잘못된 index는 IndexOutOfBoundsException입니다.

RingBufferadd, index get/set, drop, removeIf, clear를 chronological index로 제공합니다. drop(n)은 음수를 거부하고 size 이상이면 전체를 비웁니다.

Bounded memory는 backpressure가 아닙니다. Overflow가 오래된 값을 조용히 교체하므로 모든 event delivery가 필요하면 channel/queue/persistent log를 사용합니다. 여러 producer/consumer의 blocking coordination도 제공하지 않습니다.

Eviction count, capacity 도달률, snapshot size를 관찰합니다. 테스트는 wrap-around 뒤 index/iteration, concurrent access, invalid capacity, empty operation, insert/remove boundary를 포함합니다.

실행 중/대기 중 비동기 work의 capacity는 collection이 아니라 Concurrency와 lifecycle에서 다룹니다.