Stdlib index
- Captured-borrow migration worklist (3.3.3)
- Owned-bind migration worklist (8.2.7)
- Return-side title audit — the ride-through enumeration
- stdlib ownership audit
- stdlib ownership dispositions (plan 1.3.1 / 4.3.1)
aot
codec
codec / csv
codec / json
collection
- ArrayList
- BPlusTree
- Cache
- Collectors
- HashMap
- HashSet
- Heap
- ImmutableList
- ImmutableMap
- ImmutableSet
- LinkedList
- RedBlackTree
- Sort
collection / ltm
concurrent
error
- Exception
- NoOptionalValueException
- NotProvidedException
- RecoverableException
- ScopedBuildFailedException
- ScopeNotActiveException
- Throwable
- UnrecoverableException
gfx
hash
ifx
io
io / file
io / net
io / net / dns
io / net / uri
lang
lang / stream
math
math / fft
math / linalg
math / npio
math / poly
math / random
math / stats
nucleo
- Columns — the Arrow-laid-out substrate
- Fused tensor expressions — Fuse
- Table — the lazy, typed dataframe
- Tape — define-by-run autograd
- Transform intrinsics — Grad, Vmap, Jit
process
reflect
search / distance
search / fuzzy
search / ngram
session
time
- Clock
- DateTimeFormatter
- Duration
- Instant
- LocalDate
- LocalDateTime
- LocalTime
- Period
- ZonedDateTime
- ZoneId
- ZoneOffset
wire
xpu
xpu / mesh
Heap<T>
cajeta.collection.Heap — array-backed binary heap / priority queue. A
min-heap: peek() and pop() return the smallest element by the < ordering
on T, with sift-up on push and sift-down on pop, both O(log n). The
backing array grows by doubling like ArrayList. peek / pop on an empty
heap return the type’s zero value rather than throwing. Primitive T works
today; class T needs an operator< overload.
Heap<int32> h = heap Heap<int32>();
h.push(5);
h.push(1);
h.push(3);
int32 lo = h.peek(); // 1 (smallest, not removed)
int32 a = h.pop(); // 1
int32 b = h.pop(); // 3
int64 left = h.count(); // 1
boolean done = h.isEmpty(); // false
Methods
| Signature | |
|---|---|
Heap() ⚑ | Create an empty heap with an initial capacity of 16 |
int64 count() | Number of elements currently in the heap |
boolean isEmpty() | true when the heap holds no elements |
void push(T v) | Insert v, sifting it up to its ordered position |
T peek() | Smallest element without removing it, or the type’s zero value if empty |
T pop() | Remove and return the smallest element |
⚑ = @EntryPoint
See also
- Tour: HeapDemo
- Source:
runtime/src/cajeta/collection/Heap.cajeta - ArrayList — the same doubling growth strategy
- Sort — one-shot ordering of a whole array