Pure package detail
median
gno.land/p/g16m0r7rm7fv5hx0ekr7gvx8g4fr7eu08nzhk6gt/median
Indexed deployment identity with independently loaded latest RPC source. Functions and Render are realm-only RPC capabilities.
Indexed deployment
Identity
- Package path
- gno.land/p/g16m0r7rm7fv5hx0ekr7gvx8g4fr7eu08nzhk6gt/median
- Block
- 79356
- Deployed (UTC)
- Transaction
- ZABFB7Om8qQfBf0qj8UfcAFqruVnXKcVRnwkcvXptxA=
Latest RPC state
Source
package median
type Window struct {
data []int64
size int
}
func NewWindow(size int) *Window {
return &Window{data: make([]int64, 0, size), size: size}
}
func (w *Window) Push(v int64) {
w.data = append(w.data, v)
if len(w.data) > w.size {
w.data = w.data[1:]
}
}
func (w *Window) Median() int64 {
n := len(w.data)
if n == 0 {
return 0
}
sorted := make([]int64, n)
copy(sorted, w.data)
for i := 1; i < n; i++ {
key := sorted[i]
j := i - 1
for j >= 0 && sorted[j] > key {
sorted[j+1] = sorted[j]
j--
}
sorted[j+1] = key
}
if n%2 == 1 {
return sorted[n/2]
}
return (sorted[n/2-1] + sorted[n/2]) / 2
}
func (w *Window) Len() int {
return len(w.data)
}
The verified vm/qfuncs operation accepts realm paths only.
Pure packages expose source files but do not have Realm Render.