v2 / vlib / v / checker / tests / generics_undefined_operation_2.vv
33 lines · 29 sloc · 545 bytes · 0832a68bd714695d292aef2ca9b08d16b9a86516
Raw
1pub struct INode {
2mut:
3 heapindex u64
4}
5
6pub struct IHeap[T] {
7mut:
8 array []&T
9 size u64
10}
11
12pub 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
21fn (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
30fn main() {
31 heap := create_iheap[INode](3000000)
32 println(heap)
33}
34