Files
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

89 lines
1.9 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package state
import "github.com/luxfi/container/heap"
var _ StakerIterator = (*mergedIterator)(nil)
type mergedIterator struct {
initialized bool
// heap only contains iterators that have been initialized and are not
// exhausted.
heap heap.Queue[StakerIterator]
}
// Returns an iterator that returns all of the elements of [stakers] in order.
func NewMergedIterator(stakers ...StakerIterator) StakerIterator {
// Filter out iterators that are already exhausted.
i := 0
for i < len(stakers) {
staker := stakers[i]
if staker.Next() {
i++
continue
}
staker.Release()
newLength := len(stakers) - 1
stakers[i] = stakers[newLength]
stakers[newLength] = nil
stakers = stakers[:newLength]
}
it := &mergedIterator{
heap: heap.QueueOf(
func(a, b StakerIterator) bool {
return a.Value().Less(b.Value())
},
stakers...,
),
}
return it
}
func (it *mergedIterator) Next() bool {
if it.heap.Len() == 0 {
return false
}
if !it.initialized {
// Note that on the first call to Next() (i.e. here) we don't call
// Next() on the current iterator. This is because we already called
// Next() on each iterator in NewMergedIterator.
it.initialized = true
return true
}
// Update the heap root.
current, _ := it.heap.Peek()
if current.Next() {
// Calling Next() above modifies [current] so we fix the heap.
it.heap.Fix(0)
return true
}
// The old root is exhausted. Remove it from the heap.
current.Release()
it.heap.Pop()
return it.heap.Len() > 0
}
func (it *mergedIterator) Value() *Staker {
peek, _ := it.heap.Peek()
return peek.Value()
}
func (it *mergedIterator) Release() {
for it.heap.Len() > 0 {
removed, _ := it.heap.Pop()
removed.Release()
}
}
func (it *mergedIterator) Len() int {
return it.heap.Len()
}