bool-hybrid-array 9.11.3__tar.gz → 9.11.5__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bool-hybrid-array
3
- Version: 9.11.3
3
+ Version: 9.11.5
4
4
  Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
5
5
  Home-page: https://github.com/BKsell/bool-hybrid-array
6
6
  Author: 蔡靖杰
@@ -423,6 +423,27 @@ try:
423
423
  except OverflowError as e:
424
424
  print(f"\n❌ NumPy存储失败:{e}")
425
425
 
426
+ #BHA_Queue(9.11.15版本新增)
427
+
428
+ q = BHA_Queue([T, F, T, T, F])
429
+
430
+ print(f"初始化队列: {q}") # 输出:BHA_Queue([T,F,T,T,F])
431
+
432
+ q.enqueue(T)
433
+
434
+ q.enqueue(F)
435
+
436
+ print(f"入队2个元素后: {q}") # 输出:BHA_Queue([T,F,T,T,F,T,F])
437
+
438
+ # 3. 出队(dequeue,均摊O(1),仅首次触发转移)
439
+
440
+ print(f"第一次出队: {q.dequeue()}") # 输出:T(触发 self.a → self.b 转移,仅1次)
441
+
442
+ print(f"第二次出队: {q.dequeue()}") # 输出:F(直接从 self.b 弹出,纯O(1))
443
+
444
+ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
445
+
446
+
426
447
  ```
427
448
 
428
449
  ## 性能优势
@@ -490,7 +511,7 @@ except OverflowError as e:
490
511
  * **8.2.0**:支持哈希
491
512
  * **8.2.1**:修复8.2.0版本中的NameError
492
513
  * **8.2.2**:修复8.2.1版本中的IndexError
493
- - --9.0.0--:详情见上
514
+ - **9.0.0**:详情见上
494
515
  * **9.0.1**:小更新,优化optimize方法
495
516
  * **9.1.0**:新增二维数组的optimize与memory\_usage,优化二维数组的位运算,给BHA\_Bool新增__rand__、**ror**、__rxor__等等
496
517
  * **9.1.1**:修复9.1.0版本中的TypeError: unsupported operand type(s) for +: 'int' and 'method'错误
@@ -588,7 +609,8 @@ except OverflowError as e:
588
609
  * **9.11.1**:修复PyPy解释器下的保护机制过度保护bug
589
610
  * **9.11.2**:尝试修复IntHybridArray索引修改的错误
590
611
  * **9.11.3**:修复NameError: name 'lst' is not defined. Did you mean: 'list'?错误
591
-
612
+ * **9.11.4**:修复TypeError: __dict__ must be set to a dictionary, not a 'IntHybridArray'的错误
613
+ * **9.11.5**:新增BHA_Queue双栈实现队列
592
614
 
593
615
 
594
616
 
@@ -378,6 +378,27 @@ try:
378
378
  except OverflowError as e:
379
379
  print(f"\n❌ NumPy存储失败:{e}")
380
380
 
381
+ #BHA_Queue(9.11.15版本新增)
382
+
383
+ q = BHA_Queue([T, F, T, T, F])
384
+
385
+ print(f"初始化队列: {q}") # 输出:BHA_Queue([T,F,T,T,F])
386
+
387
+ q.enqueue(T)
388
+
389
+ q.enqueue(F)
390
+
391
+ print(f"入队2个元素后: {q}") # 输出:BHA_Queue([T,F,T,T,F,T,F])
392
+
393
+ # 3. 出队(dequeue,均摊O(1),仅首次触发转移)
394
+
395
+ print(f"第一次出队: {q.dequeue()}") # 输出:T(触发 self.a → self.b 转移,仅1次)
396
+
397
+ print(f"第二次出队: {q.dequeue()}") # 输出:F(直接从 self.b 弹出,纯O(1))
398
+
399
+ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
400
+
401
+
381
402
  ```
382
403
 
383
404
  ## 性能优势
@@ -445,7 +466,7 @@ except OverflowError as e:
445
466
  * **8.2.0**:支持哈希
446
467
  * **8.2.1**:修复8.2.0版本中的NameError
447
468
  * **8.2.2**:修复8.2.1版本中的IndexError
448
- - --9.0.0--:详情见上
469
+ - **9.0.0**:详情见上
449
470
  * **9.0.1**:小更新,优化optimize方法
450
471
  * **9.1.0**:新增二维数组的optimize与memory\_usage,优化二维数组的位运算,给BHA\_Bool新增__rand__、**ror**、__rxor__等等
451
472
  * **9.1.1**:修复9.1.0版本中的TypeError: unsupported operand type(s) for +: 'int' and 'method'错误
@@ -543,7 +564,8 @@ except OverflowError as e:
543
564
  * **9.11.1**:修复PyPy解释器下的保护机制过度保护bug
544
565
  * **9.11.2**:尝试修复IntHybridArray索引修改的错误
545
566
  * **9.11.3**:修复NameError: name 'lst' is not defined. Did you mean: 'list'?错误
546
-
567
+ * **9.11.4**:修复TypeError: __dict__ must be set to a dictionary, not a 'IntHybridArray'的错误
568
+ * **9.11.5**:新增BHA_Queue双栈实现队列
547
569
 
548
570
 
549
571
 
@@ -5,7 +5,7 @@ from . import core
5
5
  from .core import __builtins__,builtins
6
6
  try:from . import int_array
7
7
  except:pass
8
- __version__ = "9.11.3"
8
+ __version__ = "9.11.5"
9
9
  public_objects = []
10
10
  for name in dir(core):
11
11
  if not name.startswith("_"):
@@ -18,7 +18,7 @@ globals().update({
18
18
  for name in public_objects
19
19
  })
20
20
  try:
21
- sys.modules[__name__] = ProtectedBuiltinsDict(globals())
21
+ sys.modules[__name__] = ProtectedBuiltinsDict(globals())
22
22
  sys.modules[__name__].name = __name__
23
23
  sys.modules[__name__+'.core'] = ProtectedBuiltinsDict(core.__dict__,name = f'{__name__}.core')
24
24
  __dict__ = ProtectedBuiltinsDict(globals())
@@ -288,3 +288,24 @@ try:
288
288
  except OverflowError as e:
289
289
  print(f"\n❌ NumPy存储失败:{e}")
290
290
 
291
+
292
+ #BHA_Queue(9.11.15版本新增)
293
+
294
+ q = BHA_Queue([T, F, T, T, F])
295
+
296
+ print(f"初始化队列: {q}") # 输出:BHA_Queue([T,F,T,T,F])
297
+
298
+ q.enqueue(T)
299
+
300
+ q.enqueue(F)
301
+
302
+ print(f"入队2个元素后: {q}") # 输出:BHA_Queue([T,F,T,T,F,T,F])
303
+
304
+ # 3. 出队(dequeue,均摊O(1),仅首次触发转移)
305
+
306
+ print(f"第一次出队: {q.dequeue()}") # 输出:T(触发 self.a → self.b 转移,仅1次)
307
+
308
+ print(f"第二次出队: {q.dequeue()}") # 输出:F(直接从 self.b 弹出,纯O(1))
309
+
310
+ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
311
+
@@ -484,8 +484,8 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
484
484
  def count(self, value) -> int:
485
485
  value = bool(value)
486
486
  return sum(v == value for v in self)
487
- def optimize(self) -> None:
488
- arr = BoolHybridArr(self)
487
+ def optimize(self,*a,**k) -> BoolHybridArray:
488
+ arr = BoolHybridArr(self,*a,**k)
489
489
  self.large,self.small,self.split_index,self.is_sparse = (arr.large,arr.small,
490
490
  arr.split_index,arr.is_sparse)
491
491
  gc.collect()
@@ -533,7 +533,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
533
533
  dequeue = lambda self:self.pop(0)
534
534
  class BoolHybridArr(BoolHybridArray,metaclass=ResurrectMeta):
535
535
  __module__ = 'bool_hybrid_array'
536
- def __new__(cls, lst: Iterable, is_sparse=None, Type = None, hash_ = True) -> BoolHybridArray:
536
+ def __new__(cls, lst: Iterable = (), is_sparse=None, Type = None, hash_ = True, split_index = None) -> BoolHybridArray:
537
537
  a = isinstance(lst, (Iterator, Generator, map))
538
538
  if a:
539
539
  lst, copy1, copy2 = itertools.tee(lst, 3)
@@ -546,9 +546,10 @@ class BoolHybridArr(BoolHybridArray,metaclass=ResurrectMeta):
546
546
  return BoolHybridArray(0, 0, is_sparse=False if is_sparse is None else is_sparse)
547
547
  if is_sparse is None:
548
548
  is_sparse = true_count <= (size - true_count)
549
- split_index = int(min(size * 0.8, math.sqrt(size) * 100))
550
- split_index = math.isqrt(size) if true_count>size/3*2 or true_count<size/3 else max(split_index, 1)
551
- split_index = int(split_index) if split_index < 150e+7*2 else int(145e+7*2)
549
+ if split_index == None:
550
+ split_index = int(min(size * 0.8, math.sqrt(size) * 100))
551
+ split_index = math.isqrt(size) if true_count>size/3*2 or true_count<size/3 else max(split_index, 1)
552
+ split_index = int(split_index) if split_index < 150e+7*2 else int(145e+7*2)
552
553
  arr = BoolHybridArray(split_index = split_index, size = size, is_sparse = is_sparse, Type = Type, hash_ = F)
553
554
  small_max_idx = min(split_index, size - 1)
554
555
  if a:
@@ -718,7 +719,7 @@ class BHA_Iterator(Iterator,metaclass=ResurrectMeta):
718
719
  self.data,self.copy_data = itertools.tee(iter(data),2)
719
720
  def __next__(self):
720
721
  try:return next(self.data)
721
- except Exception as e:
722
+ except StopIteration as e:
722
723
  self.__init__(self.copy_data)
723
724
  raise e
724
725
  def __iter__(self):
@@ -738,7 +739,7 @@ class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):
738
739
  "TruesArray", "FalsesArray", "ProtectedBuiltinsDict", "builtins",
739
740
  "__builtins__", "__dict__","ResurrectMeta","math",
740
741
  "np","protected_names","BHA_Function",
741
- "__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt"),
742
+ "__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt","bool_hybrid_array"),
742
743
  name = 'builtins', **kwargs):
743
744
  super().__init__(*args, **kwargs)
744
745
  if name == 'builtins':
@@ -810,6 +811,7 @@ def Ask_arr(arr):
810
811
  return h
811
812
  else:
812
813
  return str(arr)
814
+ @BHA_Function
813
815
  def Ask_BHA(path):
814
816
  if '.bha' not in path.lower():
815
817
  path += '.bha'
@@ -838,6 +840,32 @@ def Ask_BHA(path):
838
840
  if len(temp) == 1:
839
841
  return temp[0]
840
842
  return temp
843
+ class BHA_Queue:
844
+ def __init__(self,data = (),*a,**k):
845
+ self.a = BoolHybridArr(data,*a,**k)
846
+ self.b = BoolHybridArr([],*a,**k)
847
+ def __str__(self):
848
+ return f"BHA_Queue([{','.join(itertools.chain(reversed(map(str,self.b)),self.a))}])"
849
+ __repr__ = __str__
850
+ def enqueue(self,v):
851
+ self.a.push(v)
852
+ def dequeue(self):
853
+ if self.b:return self.b.pop()
854
+ elif self.a:
855
+ tmp = BoolHybridArr(reversed(self.a))
856
+ self.b.split_index,self.b.large,self.b.small,self.b.is_sparse = tmp.split_index,tmp.large,tmp.small,tmp.is_sparse
857
+ self.a.clear()
858
+ return self.dequeue()
859
+ else:
860
+ raise IndexError("无法从空的 BHA_Queue 队列执行出队操作")
861
+ def __iter__(self):
862
+ yield from reversed(self.b)
863
+ yield from self.a
864
+ def __len__(self):
865
+ return len(self.a)+len(self.b)
866
+ def is_empty(self):
867
+ return not self
868
+ @BHA_Function
841
869
  def Create_BHA(path,arr):
842
870
  if '.bha' not in path.lower():
843
871
  path += '.bha'
@@ -97,7 +97,7 @@ class IntHybridArray(BoolHybridArray):
97
97
  def __setitem__(self, key, value):
98
98
  tmp = list(self)
99
99
  tmp[key] = value
100
- self.__dict__ = IntHybridArray(tmp)
100
+ self.__init__(tmp)
101
101
  def __iter__(self):
102
102
  return map(self.__getitem__,range(len(self)))
103
103
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bool-hybrid-array
3
- Version: 9.11.3
3
+ Version: 9.11.5
4
4
  Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
5
5
  Home-page: https://github.com/BKsell/bool-hybrid-array
6
6
  Author: 蔡靖杰
@@ -423,6 +423,27 @@ try:
423
423
  except OverflowError as e:
424
424
  print(f"\n❌ NumPy存储失败:{e}")
425
425
 
426
+ #BHA_Queue(9.11.15版本新增)
427
+
428
+ q = BHA_Queue([T, F, T, T, F])
429
+
430
+ print(f"初始化队列: {q}") # 输出:BHA_Queue([T,F,T,T,F])
431
+
432
+ q.enqueue(T)
433
+
434
+ q.enqueue(F)
435
+
436
+ print(f"入队2个元素后: {q}") # 输出:BHA_Queue([T,F,T,T,F,T,F])
437
+
438
+ # 3. 出队(dequeue,均摊O(1),仅首次触发转移)
439
+
440
+ print(f"第一次出队: {q.dequeue()}") # 输出:T(触发 self.a → self.b 转移,仅1次)
441
+
442
+ print(f"第二次出队: {q.dequeue()}") # 输出:F(直接从 self.b 弹出,纯O(1))
443
+
444
+ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
445
+
446
+
426
447
  ```
427
448
 
428
449
  ## 性能优势
@@ -490,7 +511,7 @@ except OverflowError as e:
490
511
  * **8.2.0**:支持哈希
491
512
  * **8.2.1**:修复8.2.0版本中的NameError
492
513
  * **8.2.2**:修复8.2.1版本中的IndexError
493
- - --9.0.0--:详情见上
514
+ - **9.0.0**:详情见上
494
515
  * **9.0.1**:小更新,优化optimize方法
495
516
  * **9.1.0**:新增二维数组的optimize与memory\_usage,优化二维数组的位运算,给BHA\_Bool新增__rand__、**ror**、__rxor__等等
496
517
  * **9.1.1**:修复9.1.0版本中的TypeError: unsupported operand type(s) for +: 'int' and 'method'错误
@@ -588,7 +609,8 @@ except OverflowError as e:
588
609
  * **9.11.1**:修复PyPy解释器下的保护机制过度保护bug
589
610
  * **9.11.2**:尝试修复IntHybridArray索引修改的错误
590
611
  * **9.11.3**:修复NameError: name 'lst' is not defined. Did you mean: 'list'?错误
591
-
612
+ * **9.11.4**:修复TypeError: __dict__ must be set to a dictionary, not a 'IntHybridArray'的错误
613
+ * **9.11.5**:新增BHA_Queue双栈实现队列
592
614
 
593
615
 
594
616
 
@@ -12,7 +12,7 @@ if sys.implementation.name == "pypy":
12
12
  sys.exit(f"❌ 错误:bool-hybrid-array 要求 PyPy≥7.3.10,当前版本 {pypy_ver}")
13
13
  setup(
14
14
  name="bool-hybrid-array",
15
- version="9.11.3",
15
+ version="9.11.5",
16
16
  author="蔡靖杰",
17
17
  extras_require={"int_array":[],"numba_opt": ["numba>=0.55.0"],},
18
18
  author_email="1289270215@qq.com",