@shd101wyy/yo 0.0.24 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shd101wyy/yo",
3
3
  "displayName": "Yo",
4
- "version": "0.0.24",
4
+ "version": "0.0.26",
5
5
  "main": "./out/cjs/index.cjs",
6
6
  "module": "./out/esm/index.mjs",
7
7
  "types": "./out/types/src/index.d.ts",
@@ -441,7 +441,77 @@ impl(forall(T : Type), ArrayList(T), Dispose(
441
441
  })
442
442
  ));
443
443
 
444
+ // === Iterator support ===
445
+
446
+ /**
447
+ * Value iterator for ArrayList - yields elements by value (T)
448
+ * Used by into_iter() / IntoIterator trait
449
+ */
450
+ ArrayListIter :: (fn(comptime(T) : Type) -> comptime(Type))(
451
+ struct(
452
+ _list : ArrayList(T),
453
+ _index : usize
454
+ )
455
+ );
456
+
457
+ impl(forall(T : Type), ArrayListIter(T), Iterator(
458
+ Item : T,
459
+ next : (fn(self : *(Self)) -> Option(T))(
460
+ cond(
461
+ (self._index >= self._list._length) => .None,
462
+ true => {
463
+ value := self._list.get(self._index);
464
+ self._index = (self._index + usize(1));
465
+ value
466
+ }
467
+ )
468
+ )
469
+ ));
470
+
471
+ impl(forall(T : Type), ArrayList(T),
472
+ into_iter : (fn(self : Self) -> ArrayListIter(T))(
473
+ ArrayListIter(T)(_list: self, _index: usize(0))
474
+ )
475
+ );
476
+
477
+ /**
478
+ * Pointer iterator for ArrayList - yields pointers to elements (*(T))
479
+ * Used by iter() method
480
+ */
481
+ ArrayListIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
482
+ struct(
483
+ _list : ArrayList(T),
484
+ _index : usize
485
+ )
486
+ );
487
+
488
+ impl(forall(T : Type), ArrayListIterPtr(T), Iterator(
489
+ Item : *(T),
490
+ next : (fn(self : *(Self)) -> Option(*(T)))(
491
+ cond(
492
+ (self._index >= self._list._length) => .None,
493
+ true =>
494
+ match(self._list._ptr,
495
+ .Some(ptr) => {
496
+ element_ptr := (ptr &+ self._index);
497
+ self._index = (self._index + usize(1));
498
+ .Some(element_ptr)
499
+ },
500
+ .None => .None
501
+ )
502
+ )
503
+ )
504
+ ));
505
+
506
+ impl(forall(T : Type), ArrayList(T),
507
+ iter : (fn(self : *(Self)) -> ArrayListIterPtr(T))(
508
+ ArrayListIterPtr(T)(_list: self.*, _index: usize(0))
509
+ )
510
+ );
511
+
444
512
  export
445
513
  ArrayList,
446
- ArrayListError
514
+ ArrayListError,
515
+ ArrayListIter,
516
+ ArrayListIterPtr
447
517
  ;
@@ -130,8 +130,126 @@ impl(forall(K : Type, V : Type), BTreeMap(K, V),
130
130
  true => .Some(self._entries.get((self._entries.len() - usize(1))).unwrap())
131
131
  )
132
132
  )
133
+ );
134
+
135
+ /**
136
+ * Value iterator for BTreeMap - yields BTreeEntry(K, V) in sorted key order
137
+ */
138
+ BTreeMapIter :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
139
+ struct(
140
+ _entries : ArrayList(BTreeEntry(K, V)),
141
+ _index : usize
142
+ )
143
+ );
144
+
145
+ impl(forall(K : Type, V : Type), BTreeMapIter(K, V), Iterator(
146
+ Item : BTreeEntry(K, V),
147
+ next : (fn(self : *(Self)) -> Option(BTreeEntry(K, V)))(
148
+ cond(
149
+ (self._index >= self._entries.len()) => .None,
150
+ true => {
151
+ entry := self._entries.get(self._index).unwrap();
152
+ self._index = (self._index + usize(1));
153
+ .Some(entry)
154
+ }
155
+ )
156
+ )
157
+ ));
158
+
159
+ impl(forall(K : Type, V : Type), BTreeMap(K, V),
160
+ into_iter : (fn(self : Self) -> BTreeMapIter(K, V))(
161
+ BTreeMapIter(K, V)(_entries: self._entries, _index: usize(0))
162
+ )
163
+ );
164
+
165
+ /**
166
+ * Pointer iterator for BTreeMap - yields pointers to BTreeEntry(K, V) in sorted key order
167
+ */
168
+ BTreeMapIterPtr :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
169
+ struct(
170
+ _entries : ArrayList(BTreeEntry(K, V)),
171
+ _index : usize
172
+ )
173
+ );
133
174
 
134
- // TODO: Add iteration via Iterator trait once supported.
175
+ impl(forall(K : Type, V : Type), BTreeMapIterPtr(K, V), Iterator(
176
+ Item : *(BTreeEntry(K, V)),
177
+ next : (fn(self : *(Self)) -> Option(*(BTreeEntry(K, V))))(
178
+ cond(
179
+ (self._index >= self._entries.len()) => .None,
180
+ true =>
181
+ match(self._entries._ptr,
182
+ .Some(ptr) => {
183
+ element_ptr := (ptr &+ self._index);
184
+ self._index = (self._index + usize(1));
185
+ .Some(element_ptr)
186
+ },
187
+ .None => .None
188
+ )
189
+ )
190
+ )
191
+ ));
192
+
193
+ impl(forall(K : Type, V : Type), BTreeMap(K, V),
194
+ iter : (fn(self : *(Self)) -> BTreeMapIterPtr(K, V))(
195
+ BTreeMapIterPtr(K, V)(_entries: self.*._entries, _index: usize(0))
196
+ )
197
+ );
198
+
199
+ /**
200
+ * Keys iterator - wraps BTreeMapIter and yields only keys in sorted order
201
+ */
202
+ BTreeMapKeys :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
203
+ struct(
204
+ _inner : BTreeMapIter(K, V)
205
+ )
206
+ );
207
+
208
+ impl(forall(K : Type, V : Type), BTreeMapKeys(K, V), Iterator(
209
+ Item : K,
210
+ next : (fn(self : *(Self)) -> Option(K))(
211
+ match(self._inner.next(),
212
+ .None => .None,
213
+ .Some(entry) => .Some(entry.key)
214
+ )
215
+ )
216
+ ));
217
+
218
+ impl(forall(K : Type, V : Type), BTreeMap(K, V),
219
+ keys : (fn(self : Self) -> BTreeMapKeys(K, V))(
220
+ BTreeMapKeys(K, V)(_inner: BTreeMapIter(K, V)(_entries: self._entries, _index: usize(0)))
221
+ )
222
+ );
223
+
224
+ /**
225
+ * Values iterator - wraps BTreeMapIter and yields only values in sorted key order
226
+ */
227
+ BTreeMapValues :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
228
+ struct(
229
+ _inner : BTreeMapIter(K, V)
230
+ )
231
+ );
232
+
233
+ impl(forall(K : Type, V : Type), BTreeMapValues(K, V), Iterator(
234
+ Item : V,
235
+ next : (fn(self : *(Self)) -> Option(V))(
236
+ match(self._inner.next(),
237
+ .None => .None,
238
+ .Some(entry) => .Some(entry.value)
239
+ )
240
+ )
241
+ ));
242
+
243
+ impl(forall(K : Type, V : Type), BTreeMap(K, V),
244
+ values : (fn(self : Self) -> BTreeMapValues(K, V))(
245
+ BTreeMapValues(K, V)(_inner: BTreeMapIter(K, V)(_entries: self._entries, _index: usize(0)))
246
+ )
135
247
  );
136
248
 
137
- export BTreeMap;
249
+ export
250
+ BTreeMap,
251
+ BTreeMapIter,
252
+ BTreeMapIterPtr,
253
+ BTreeMapKeys,
254
+ BTreeMapValues
255
+ ;
@@ -179,4 +179,79 @@ impl(forall(T : Type), Deque(T), Dispose(
179
179
  })
180
180
  ));
181
181
 
182
- export Deque;
182
+ /**
183
+ * Value iterator for Deque - yields elements by value (T)
184
+ * Traverses the circular buffer in logical order.
185
+ */
186
+ DequeIter :: (fn(comptime(T) : Type) -> comptime(Type))(
187
+ struct(
188
+ _deque : Deque(T),
189
+ _pos : usize,
190
+ _remaining : usize
191
+ )
192
+ );
193
+
194
+ impl(forall(T : Type), DequeIter(T), Iterator(
195
+ Item : T,
196
+ next : (fn(self : *(Self)) -> Option(T))(
197
+ cond(
198
+ (self._remaining == usize(0)) => .None,
199
+ true => {
200
+ idx := ((self._deque._head + self._pos) % self._deque._capacity);
201
+ buf := self._deque._buf.unwrap();
202
+ value := (buf &+ idx).*;
203
+ self._pos = (self._pos + usize(1));
204
+ self._remaining = (self._remaining - usize(1));
205
+ .Some(value)
206
+ }
207
+ )
208
+ )
209
+ ));
210
+
211
+ impl(forall(T : Type), Deque(T),
212
+ into_iter : (fn(self : Self) -> DequeIter(T))(
213
+ DequeIter(T)(_deque: self, _pos: usize(0), _remaining: self._len)
214
+ )
215
+ );
216
+
217
+ /**
218
+ * Pointer iterator for Deque - yields pointers to elements (*(T))
219
+ * Yields pointers into the circular buffer. Pointers are valid as long as
220
+ * the deque is not modified during iteration.
221
+ */
222
+ DequeIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
223
+ struct(
224
+ _deque : Deque(T),
225
+ _pos : usize,
226
+ _remaining : usize
227
+ )
228
+ );
229
+
230
+ impl(forall(T : Type), DequeIterPtr(T), Iterator(
231
+ Item : *(T),
232
+ next : (fn(self : *(Self)) -> Option(*(T)))(
233
+ cond(
234
+ (self._remaining == usize(0)) => .None,
235
+ true => {
236
+ idx := ((self._deque._head + self._pos) % self._deque._capacity);
237
+ buf := self._deque._buf.unwrap();
238
+ element_ptr := (buf &+ idx);
239
+ self._pos = (self._pos + usize(1));
240
+ self._remaining = (self._remaining - usize(1));
241
+ .Some(element_ptr)
242
+ }
243
+ )
244
+ )
245
+ ));
246
+
247
+ impl(forall(T : Type), Deque(T),
248
+ iter : (fn(self : *(Self)) -> DequeIterPtr(T))(
249
+ DequeIterPtr(T)(_deque: self.*, _pos: usize(0), _remaining: self.*._len)
250
+ )
251
+ );
252
+
253
+ export
254
+ Deque,
255
+ DequeIter,
256
+ DequeIterPtr
257
+ ;
@@ -565,8 +565,144 @@ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V),
565
565
  })
566
566
  ));
567
567
 
568
+ /**
569
+ * Value iterator for HashMap - yields Bucket(K, V) by value
570
+ * Scans ctrl bytes to find occupied slots.
571
+ */
572
+ HashMapIter :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
573
+ struct(
574
+ _map : HashMap(K, V),
575
+ _index : usize
576
+ )
577
+ );
578
+
579
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapIter(K, V), Iterator(
580
+ Item : Bucket(K, V),
581
+ next : (fn(self : *(Self)) -> Option(Bucket(K, V)))(
582
+ cond(
583
+ (self._map.capacity == usize(0)) => .None,
584
+ true => {
585
+ ctrl_ptr := self._map.ctrl.unwrap();
586
+ data_ptr := self._map.data.unwrap();
587
+ result := Option(Bucket(K, V)).None;
588
+ while ((self._index < self._map.capacity) && result.is_none()), (self._index = (self._index + usize(1))), {
589
+ ctrl_byte := (ctrl_ptr &+ self._index).*;
590
+ cond(
591
+ ((ctrl_byte != CTRL_EMPTY) && (ctrl_byte != CTRL_DELETED)) => {
592
+ result = .Some((data_ptr &+ self._index).*);
593
+ },
594
+ true => ()
595
+ );
596
+ };
597
+ result
598
+ }
599
+ )
600
+ )
601
+ ));
602
+
603
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V),
604
+ into_iter : (fn(self : Self) -> HashMapIter(K, V))(
605
+ HashMapIter(K, V)(_map: self, _index: usize(0))
606
+ )
607
+ );
608
+
609
+ /**
610
+ * Pointer iterator for HashMap - yields pointers to Bucket(K, V)
611
+ * Pointers are valid as long as the map is not modified during iteration.
612
+ */
613
+ HashMapIterPtr :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
614
+ struct(
615
+ _map : HashMap(K, V),
616
+ _index : usize
617
+ )
618
+ );
619
+
620
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapIterPtr(K, V), Iterator(
621
+ Item : *(Bucket(K, V)),
622
+ next : (fn(self : *(Self)) -> Option(*(Bucket(K, V))))(
623
+ cond(
624
+ (self._map.capacity == usize(0)) => .None,
625
+ true => {
626
+ ctrl_ptr := self._map.ctrl.unwrap();
627
+ data_ptr := self._map.data.unwrap();
628
+ result := Option(*(Bucket(K, V))).None;
629
+ while ((self._index < self._map.capacity) && result.is_none()), (self._index = (self._index + usize(1))), {
630
+ ctrl_byte := (ctrl_ptr &+ self._index).*;
631
+ cond(
632
+ ((ctrl_byte != CTRL_EMPTY) && (ctrl_byte != CTRL_DELETED)) => {
633
+ result = .Some((data_ptr &+ self._index));
634
+ },
635
+ true => ()
636
+ );
637
+ };
638
+ result
639
+ }
640
+ )
641
+ )
642
+ ));
643
+
644
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V),
645
+ iter : (fn(self : *(Self)) -> HashMapIterPtr(K, V))(
646
+ HashMapIterPtr(K, V)(_map: self.*, _index: usize(0))
647
+ )
648
+ );
649
+
650
+ /**
651
+ * Keys iterator - wraps HashMapIter and yields only the keys
652
+ */
653
+ HashMapKeys :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
654
+ struct(
655
+ _inner : HashMapIter(K, V)
656
+ )
657
+ );
658
+
659
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapKeys(K, V), Iterator(
660
+ Item : K,
661
+ next : (fn(self : *(Self)) -> Option(K))(
662
+ match(self._inner.next(),
663
+ .None => .None,
664
+ .Some(bucket) => .Some(bucket.key)
665
+ )
666
+ )
667
+ ));
668
+
669
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V),
670
+ keys : (fn(self : Self) -> HashMapKeys(K, V))(
671
+ HashMapKeys(K, V)(_inner: HashMapIter(K, V)(_map: self, _index: usize(0)))
672
+ )
673
+ );
674
+
675
+ /**
676
+ * Values iterator - wraps HashMapIter and yields only the values
677
+ */
678
+ HashMapValues :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
679
+ struct(
680
+ _inner : HashMapIter(K, V)
681
+ )
682
+ );
683
+
684
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapValues(K, V), Iterator(
685
+ Item : V,
686
+ next : (fn(self : *(Self)) -> Option(V))(
687
+ match(self._inner.next(),
688
+ .None => .None,
689
+ .Some(bucket) => .Some(bucket.value)
690
+ )
691
+ )
692
+ ));
693
+
694
+ impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V),
695
+ values : (fn(self : Self) -> HashMapValues(K, V))(
696
+ HashMapValues(K, V)(_inner: HashMapIter(K, V)(_map: self, _index: usize(0)))
697
+ )
698
+ );
699
+
568
700
  export
569
701
  HashMap,
570
702
  HashMapError,
571
- Bucket
703
+ Bucket,
704
+ HashMapIter,
705
+ HashMapIterPtr,
706
+ HashMapKeys,
707
+ HashMapValues
572
708
  ;
@@ -781,7 +781,91 @@ impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSet(T), Dispose(
781
781
  )
782
782
  ));
783
783
 
784
+ /**
785
+ * Value iterator for HashSet - yields elements by value (T)
786
+ * Scans ctrl bytes to find occupied slots.
787
+ */
788
+ HashSetIter :: (fn(comptime(T) : Type) -> comptime(Type))(
789
+ struct(
790
+ _set : HashSet(T),
791
+ _index : usize
792
+ )
793
+ );
794
+
795
+ impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSetIter(T), Iterator(
796
+ Item : T,
797
+ next : (fn(self : *(Self)) -> Option(T))(
798
+ cond(
799
+ (self._set.capacity == usize(0)) => .None,
800
+ true => {
801
+ ctrl_ptr := self._set.ctrl.unwrap();
802
+ data_ptr := self._set.data.unwrap();
803
+ result := Option(T).None;
804
+ while ((self._index < self._set.capacity) && result.is_none()), (self._index = (self._index + usize(1))), {
805
+ ctrl_byte := (ctrl_ptr &+ self._index).*;
806
+ cond(
807
+ ((ctrl_byte != CTRL_EMPTY) && (ctrl_byte != CTRL_DELETED)) => {
808
+ result = .Some((data_ptr &+ self._index).*);
809
+ },
810
+ true => ()
811
+ );
812
+ };
813
+ result
814
+ }
815
+ )
816
+ )
817
+ ));
818
+
819
+ impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSet(T),
820
+ into_iter : (fn(self : Self) -> HashSetIter(T))(
821
+ HashSetIter(T)(_set: self, _index: usize(0))
822
+ )
823
+ );
824
+
825
+ /**
826
+ * Pointer iterator for HashSet - yields pointers to elements (*(T))
827
+ * Pointers are valid as long as the set is not modified during iteration.
828
+ */
829
+ HashSetIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
830
+ struct(
831
+ _set : HashSet(T),
832
+ _index : usize
833
+ )
834
+ );
835
+
836
+ impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSetIterPtr(T), Iterator(
837
+ Item : *(T),
838
+ next : (fn(self : *(Self)) -> Option(*(T)))(
839
+ cond(
840
+ (self._set.capacity == usize(0)) => .None,
841
+ true => {
842
+ ctrl_ptr := self._set.ctrl.unwrap();
843
+ data_ptr := self._set.data.unwrap();
844
+ result := Option(*(T)).None;
845
+ while ((self._index < self._set.capacity) && result.is_none()), (self._index = (self._index + usize(1))), {
846
+ ctrl_byte := (ctrl_ptr &+ self._index).*;
847
+ cond(
848
+ ((ctrl_byte != CTRL_EMPTY) && (ctrl_byte != CTRL_DELETED)) => {
849
+ result = .Some((data_ptr &+ self._index));
850
+ },
851
+ true => ()
852
+ );
853
+ };
854
+ result
855
+ }
856
+ )
857
+ )
858
+ ));
859
+
860
+ impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSet(T),
861
+ iter : (fn(self : *(Self)) -> HashSetIterPtr(T))(
862
+ HashSetIterPtr(T)(_set: self.*, _index: usize(0))
863
+ )
864
+ );
865
+
784
866
  export
785
867
  HashSet,
786
- HashSetError
868
+ HashSetError,
869
+ HashSetIter,
870
+ HashSetIterPtr
787
871
  ;
@@ -438,8 +438,68 @@ impl(forall(T : Type), LinkedList(T), Dispose(
438
438
  )
439
439
  ));
440
440
 
441
+ /**
442
+ * Value iterator for LinkedList - yields elements by value (T)
443
+ * Traverses the linked list following node.next pointers.
444
+ */
445
+ LinkedListIter :: (fn(comptime(T) : Type) -> comptime(Type))(
446
+ struct(
447
+ _current : Option(Node(T))
448
+ )
449
+ );
450
+
451
+ impl(forall(T : Type), LinkedListIter(T), Iterator(
452
+ Item : T,
453
+ next : (fn(self : *(Self)) -> Option(T))(
454
+ match(self._current,
455
+ .None => .None,
456
+ .Some(node) => {
457
+ self._current = node.next;
458
+ .Some(node.value)
459
+ }
460
+ )
461
+ )
462
+ ));
463
+
464
+ impl(forall(T : Type), LinkedList(T),
465
+ into_iter : (fn(self : Self) -> LinkedListIter(T))(
466
+ LinkedListIter(T)(_current: self.head)
467
+ )
468
+ );
469
+
470
+ /**
471
+ * Pointer iterator for LinkedList - yields pointers to elements (*(T))
472
+ * Yields &(node.value) for each node. Pointers are valid as long as
473
+ * the list is not modified during iteration.
474
+ */
475
+ LinkedListIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
476
+ struct(
477
+ _current : Option(Node(T))
478
+ )
479
+ );
480
+
481
+ impl(forall(T : Type), LinkedListIterPtr(T), Iterator(
482
+ Item : *(T),
483
+ next : (fn(self : *(Self)) -> Option(*(T)))(
484
+ match(self._current,
485
+ .None => .None,
486
+ .Some(node) => {
487
+ self._current = node.next;
488
+ .Some(&(node.value))
489
+ }
490
+ )
491
+ )
492
+ ));
493
+
494
+ impl(forall(T : Type), LinkedList(T),
495
+ iter : (fn(self : *(Self)) -> LinkedListIterPtr(T))(
496
+ LinkedListIterPtr(T)(_current: self.*.head)
497
+ )
498
+ );
441
499
 
442
500
  export
443
501
  LinkedList,
444
- LinkedListError
502
+ LinkedListError,
503
+ LinkedListIter,
504
+ LinkedListIterPtr
445
505
  ;
@@ -118,4 +118,73 @@ impl(forall(T : Type), PriorityQueue(T),
118
118
  })
119
119
  );
120
120
 
121
- export PriorityQueue;
121
+ /**
122
+ * Value iterator for PriorityQueue - yields elements in heap (arbitrary) order
123
+ * Note: This iterates in internal storage order, NOT sorted order.
124
+ */
125
+ PriorityQueueIter :: (fn(comptime(T) : Type) -> comptime(Type))(
126
+ struct(
127
+ _data : ArrayList(T),
128
+ _index : usize
129
+ )
130
+ );
131
+
132
+ impl(forall(T : Type), PriorityQueueIter(T), Iterator(
133
+ Item : T,
134
+ next : (fn(self : *(Self)) -> Option(T))(
135
+ cond(
136
+ (self._index >= self._data.len()) => .None,
137
+ true => {
138
+ value := self._data.get(self._index).unwrap();
139
+ self._index = (self._index + usize(1));
140
+ .Some(value)
141
+ }
142
+ )
143
+ )
144
+ ));
145
+
146
+ impl(forall(T : Type), PriorityQueue(T),
147
+ into_iter : (fn(self : Self) -> PriorityQueueIter(T))(
148
+ PriorityQueueIter(T)(_data: self._data, _index: usize(0))
149
+ )
150
+ );
151
+
152
+ /**
153
+ * Pointer iterator for PriorityQueue - yields pointers to elements in heap order
154
+ */
155
+ PriorityQueueIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
156
+ struct(
157
+ _data : ArrayList(T),
158
+ _index : usize
159
+ )
160
+ );
161
+
162
+ impl(forall(T : Type), PriorityQueueIterPtr(T), Iterator(
163
+ Item : *(T),
164
+ next : (fn(self : *(Self)) -> Option(*(T)))(
165
+ cond(
166
+ (self._index >= self._data.len()) => .None,
167
+ true =>
168
+ match(self._data._ptr,
169
+ .Some(ptr) => {
170
+ element_ptr := (ptr &+ self._index);
171
+ self._index = (self._index + usize(1));
172
+ .Some(element_ptr)
173
+ },
174
+ .None => .None
175
+ )
176
+ )
177
+ )
178
+ ));
179
+
180
+ impl(forall(T : Type), PriorityQueue(T),
181
+ iter : (fn(self : *(Self)) -> PriorityQueueIterPtr(T))(
182
+ PriorityQueueIterPtr(T)(_data: self.*._data, _index: usize(0))
183
+ )
184
+ );
185
+
186
+ export
187
+ PriorityQueue,
188
+ PriorityQueueIter,
189
+ PriorityQueueIterPtr
190
+ ;