From 38c0eb6bea5da0c731cf06a4d8962d2d509d3baf Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 12 Oct 2023 22:17:26 +0800 Subject: [PATCH] ... --- include/pocketpy/namedict.h | 80 +++++++++++++++++-------------------- tests/98_misc.py | 11 ++++- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/include/pocketpy/namedict.h b/include/pocketpy/namedict.h index 50fca846..a2cd3543 100644 --- a/include/pocketpy/namedict.h +++ b/include/pocketpy/namedict.h @@ -13,6 +13,8 @@ constexpr T default_invalid_value(){ else return Discarded(); } +#define PK_LOOP_12(B) B(0) B(1) B(2) B(3) B(4) B(5) B(6) B(7) B(8) B(9) B(10) B(11) + template struct SmallNameDict{ using K = StrName; @@ -29,13 +31,14 @@ struct SmallNameDict{ bool try_set(K key, V val){ int slot = -1; - for(int i=0; i(); } V* try_get_2(K key) { - for(int i=0; i void apply(Func func) const { - for(int i=0; i()){ + throw std::runtime_error(fmt("NameDict key not found: ", key.escape())); + } + return val; + } + void clear(){ if(is_small()) _small.clear(); else _large.clear(); diff --git a/tests/98_misc.py b/tests/98_misc.py index 3776a487..9536d11e 100644 --- a/tests/98_misc.py +++ b/tests/98_misc.py @@ -24,4 +24,13 @@ a %= 3 assert a == 2 a ^= 0xf0 -assert a == 242 \ No newline at end of file +assert a == 242 + +# incremental set +class A: pass + +for i in range(ord('a'), ord('z')+1): + setattr(A, chr(i), i) + +assert A.a == ord('a') +assert A.z == ord('z')