| 1 | pub struct INode { |
| 2 | mut: |
| 3 | heapindex u64 |
| 4 | } |
| 5 | |
| 6 | pub struct IHeap[T] { |
| 7 | mut: |
| 8 | array []&T |
| 9 | size u64 |
| 10 | } |
| 11 | |
| 12 | pub fn create_iheap[T](capacity int) &IHeap[T] { |
| 13 | mut h := &IHeap[T]{ |
| 14 | array: []&T{cap: capacity} |
| 15 | size: 0 |
| 16 | } |
| 17 | h.array << &T(unsafe { nil }) |
| 18 | return h |
| 19 | } |
| 20 | |
| 21 | fn (mut h IHeap[T]) percolateup(hl u64, mut element T) { |
| 22 | mut hole := hl |
| 23 | for hole > 1 && element < h.array[int(hole / 2)] { |
| 24 | // ^ Notice that '<' was not defined |
| 25 | println("didnt define '<' for the INode") |
| 26 | hole /= 2 |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | fn main() { |
| 31 | heap := create_iheap[INode](3000000) |
| 32 | println(heap) |
| 33 | } |
| 34 | |