@shd101wyy/yo 0.1.32 → 0.1.33

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.1.32",
4
+ "version": "0.1.33",
5
5
  "main": "./out/cjs/index.cjs",
6
6
  "module": "./out/esm/index.mjs",
7
7
  "types": "./out/types/src/index.d.ts",
@@ -573,11 +573,18 @@ impl(
573
573
  )
574
574
  );
575
575
  /**
576
- * Keys iterator - wraps HashMapIter and yields only the keys
576
+ * Keys iterator - scans ctrl bytes directly and yields only the keys.
577
+ *
578
+ * NOTE: This held a wrapped `_inner : HashMapIter(K, V)` and delegated
579
+ * `self._inner.next()` — but a method call on a struct FIELD of `ref(self)`
580
+ * advances a COPY of the field, so `_index` never moved and manual
581
+ * `it.next()` loops yielded the first key forever (`for(...)` masked it).
582
+ * Scan directly instead, mirroring `HashMapIterPtr`.
577
583
  */
578
584
  HashMapKeys :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
579
585
  struct(
580
- _inner : HashMapIter(K, V)
586
+ _map : HashMap(K, V),
587
+ _index : usize
581
588
  )
582
589
  );
583
590
  impl(
@@ -587,10 +594,23 @@ impl(
587
594
  Iterator(
588
595
  Item : K,
589
596
  next : (fn(ref(self) : Self) -> Option(K))(
590
- match(
591
- self._inner.next(),
592
- .None =>.None,
593
- .Some(bucket) =>.Some(bucket.key)
597
+ cond(
598
+ (self._map.capacity == usize(0)) =>.None,
599
+ true => {
600
+ ctrl_ptr := self._map.ctrl.unwrap();
601
+ data_ptr := self._map.data.unwrap();
602
+ result := Option(K).None;
603
+ while((self._index < self._map.capacity) && result.is_none(), self._index = (self._index + usize(1)), {
604
+ ctrl_byte := (ctrl_ptr &+ self._index).*;
605
+ cond(
606
+ ((ctrl_byte != CTRL_EMPTY) && (ctrl_byte != CTRL_DELETED)) => {
607
+ result =.Some((data_ptr &+ self._index).*.key);
608
+ },
609
+ true => ()
610
+ );
611
+ });
612
+ result
613
+ }
594
614
  )
595
615
  )
596
616
  )
@@ -600,15 +620,19 @@ impl(
600
620
  where(K <: (Eq(K), Hash)),
601
621
  HashMap(K, V),
602
622
  keys : (fn(self : Self) -> HashMapKeys(K, V))(
603
- HashMapKeys(K, V)(_inner : HashMapIter(K, V)(_map : self, _index : usize(0)))
623
+ HashMapKeys(K, V)(_map : self, _index : usize(0))
604
624
  )
605
625
  );
606
626
  /**
607
- * Values iterator - wraps HashMapIter and yields only the values
627
+ * Values iterator - scans ctrl bytes directly and yields only the values.
628
+ *
629
+ * NOTE: Same direct-scan structure as `HashMapKeys` — see the note there for
630
+ * why the wrapped-`_inner` delegation form was replaced.
608
631
  */
609
632
  HashMapValues :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
610
633
  struct(
611
- _inner : HashMapIter(K, V)
634
+ _map : HashMap(K, V),
635
+ _index : usize
612
636
  )
613
637
  );
614
638
  impl(
@@ -618,10 +642,23 @@ impl(
618
642
  Iterator(
619
643
  Item : V,
620
644
  next : (fn(ref(self) : Self) -> Option(V))(
621
- match(
622
- self._inner.next(),
623
- .None =>.None,
624
- .Some(bucket) =>.Some(bucket.value)
645
+ cond(
646
+ (self._map.capacity == usize(0)) =>.None,
647
+ true => {
648
+ ctrl_ptr := self._map.ctrl.unwrap();
649
+ data_ptr := self._map.data.unwrap();
650
+ result := Option(V).None;
651
+ while((self._index < self._map.capacity) && result.is_none(), self._index = (self._index + usize(1)), {
652
+ ctrl_byte := (ctrl_ptr &+ self._index).*;
653
+ cond(
654
+ ((ctrl_byte != CTRL_EMPTY) && (ctrl_byte != CTRL_DELETED)) => {
655
+ result =.Some((data_ptr &+ self._index).*.value);
656
+ },
657
+ true => ()
658
+ );
659
+ });
660
+ result
661
+ }
625
662
  )
626
663
  )
627
664
  )
@@ -631,7 +668,7 @@ impl(
631
668
  where(K <: (Eq(K), Hash)),
632
669
  HashMap(K, V),
633
670
  values : (fn(self : Self) -> HashMapValues(K, V))(
634
- HashMapValues(K, V)(_inner : HashMapIter(K, V)(_map : self, _index : usize(0)))
671
+ HashMapValues(K, V)(_map : self, _index : usize(0))
635
672
  )
636
673
  );
637
674
  impl(
package/std/prelude.yo CHANGED
@@ -6813,6 +6813,10 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
6813
6813
  )
6814
6814
  });
6815
6815
  derive_rule(Eq, __derive_eq);
6816
+ // `Pragma` (defined near the top) is compared by `==` in the compiler's
6817
+ // memory-safety pragma registry. Derived here, once the `Eq` derive rule
6818
+ // is registered.
6819
+ derive(Pragma, Eq(Pragma));
6816
6820
  // --- derive_rule for Clone ---
6817
6821
  __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(trait_params) : ComptimeList(Expr)) -> comptime(Expr))({
6818
6822
  info :: Type.get_info(T);