bool-hybrid-array 9.10.22__tar.gz → 9.11.1__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.
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/PKG-INFO +25 -3
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/README.md +19 -2
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array/__init__.py +8 -6
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array/__main__.py +4 -0
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array/core.py +47 -22
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array/int_array/__init__.py +11 -20
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array.egg-info/PKG-INFO +25 -3
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array.egg-info/requires.txt +3 -0
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/setup.py +11 -4
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/LICENSE +0 -0
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array//347/247/230/345/257/206.md" +0 -0
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array.egg-info/SOURCES.txt +0 -0
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array.egg-info/dependency_links.txt +0 -0
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array.egg-info/top_level.txt +0 -0
- {bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bool-hybrid-array
|
|
3
|
-
Version: 9.
|
|
3
|
+
Version: 9.11.1
|
|
4
4
|
Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
|
|
5
5
|
Home-page: https://github.com/BKsell/bool-hybrid-array
|
|
6
6
|
Author: 蔡靖杰
|
|
@@ -17,6 +17,9 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
23
|
Classifier: License :: OSI Approved :: MIT License
|
|
21
24
|
Classifier: Operating System :: OS Independent
|
|
22
25
|
Requires-Python: >=3.8
|
|
@@ -24,6 +27,8 @@ Description-Content-Type: text/markdown
|
|
|
24
27
|
License-File: LICENSE
|
|
25
28
|
Requires-Dist: numpy>=1.19.0
|
|
26
29
|
Provides-Extra: int-array
|
|
30
|
+
Provides-Extra: numba-opt
|
|
31
|
+
Requires-Dist: numba>=0.55.0; extra == "numba-opt"
|
|
27
32
|
Dynamic: author
|
|
28
33
|
Dynamic: author-email
|
|
29
34
|
Dynamic: classifier
|
|
@@ -40,10 +45,17 @@ Dynamic: summary
|
|
|
40
45
|
|
|
41
46
|
# BoolHybridArray:高效的布尔混合数组库
|
|
42
47
|
|
|
48
|
+
<!-- 月下载量(核心推荐)+ 周下载量 + 总下载量 -->
|
|
49
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
50
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
51
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
52
|
+
|
|
43
53
|
一个专为布尔值优化的数组类,能够根据数据特征自动在密集存储和稀疏存储模式间切换,兼顾性能和内存效率。
|
|
44
54
|
|
|
45
55
|
## ***注:大版本号更新并非不兼容更新,而是重大更新***
|
|
46
56
|
|
|
57
|
+
注:当API完全稳定时就会发布版本规则较严谨的new-1.0.0版本,预期为10.x版本结束后
|
|
58
|
+
|
|
47
59
|
***注意:目前社区中若存在名称类似(如包含 “bool-hybrid-array”+ 后缀、boolean\_array、validate.io-boolean-array)的库,均与本项目(bool-hybrid-array)无关联,本项目的所有功能设计、代码实现均为独立开发;***
|
|
48
60
|
***其他平台里的类似名库绝不是我的库***
|
|
49
61
|
|
|
@@ -141,7 +153,7 @@ big_arr = BoolHybridArr([i % 100 == 0 for i in range(10000)])
|
|
|
141
153
|
|
|
142
154
|
# 查看存储模式(此时应为稀疏模式)
|
|
143
155
|
|
|
144
|
-
print(repr(big_arr)) # 输出: BoolHybridArray(split_index=100,size=10000,is_sparse=True,small_len=
|
|
156
|
+
print(repr(big_arr)) # 输出: BoolHybridArray(split_index=100, size=10000, is_sparse=True, small_len=101, large_len=98)
|
|
145
157
|
|
|
146
158
|
# 自动优化存储
|
|
147
159
|
|
|
@@ -572,6 +584,12 @@ except OverflowError as e:
|
|
|
572
584
|
* **9.10.20**:优化性能,增加BHA_jit_log日志
|
|
573
585
|
* **9.10.21**:优化Ask_BHA,移除BHA_jit_log日志
|
|
574
586
|
* **9.10.22**:进一步优化Ask_BHA的性能
|
|
587
|
+
* **9.11.0**:新增对7.3.10以上版本的PyPy解释器的支持
|
|
588
|
+
* **9.11.1**:修复PyPy解释器下的保护机制过度保护bug
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
575
593
|
|
|
576
594
|
|
|
577
595
|
## **彩蛋:**
|
|
@@ -586,7 +604,11 @@ except OverflowError as e:
|
|
|
586
604
|
* A:BoolHybridArray是本库中的**核心类**,所有函数都是围绕他进行的,但需要`split_index`,`size`,`is_sparse`;
|
|
587
605
|
BoolHybridArr是一个**函数**,用于把一个可迭代对象转为`BoolHybridArray`类
|
|
588
606
|
* Q:为什么不建议把太大的本类型数组打印?
|
|
589
|
-
* A
|
|
607
|
+
* A:虽然BoolHybridArray类型数组省内存,但字符串不省内存,一个`True`要4字节,一个`False`要5字节,连逗号都要占1字节(`numpy.ndarray`:我都比字符串省内存)
|
|
608
|
+
- Q:为什么使用在Windows终端使用PyPy时建议先调用`chcp 65001`再启动PyPy?
|
|
609
|
+
* A:因为本库有很多的的中文报错和打印,项目里也可能会有。Windows终端里的PyPy默认是GBK编码,有中文时会乱码。chcp 65001可以切换到UTF-8编码,防止乱码。
|
|
610
|
+
|
|
611
|
+
|
|
590
612
|
|
|
591
613
|
## 源代码和原理
|
|
592
614
|
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
# BoolHybridArray:高效的布尔混合数组库
|
|
2
2
|
|
|
3
|
+
<!-- 月下载量(核心推荐)+ 周下载量 + 总下载量 -->
|
|
4
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
5
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
6
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
7
|
+
|
|
3
8
|
一个专为布尔值优化的数组类,能够根据数据特征自动在密集存储和稀疏存储模式间切换,兼顾性能和内存效率。
|
|
4
9
|
|
|
5
10
|
## ***注:大版本号更新并非不兼容更新,而是重大更新***
|
|
6
11
|
|
|
12
|
+
注:当API完全稳定时就会发布版本规则较严谨的new-1.0.0版本,预期为10.x版本结束后
|
|
13
|
+
|
|
7
14
|
***注意:目前社区中若存在名称类似(如包含 “bool-hybrid-array”+ 后缀、boolean\_array、validate.io-boolean-array)的库,均与本项目(bool-hybrid-array)无关联,本项目的所有功能设计、代码实现均为独立开发;***
|
|
8
15
|
***其他平台里的类似名库绝不是我的库***
|
|
9
16
|
|
|
@@ -101,7 +108,7 @@ big_arr = BoolHybridArr([i % 100 == 0 for i in range(10000)])
|
|
|
101
108
|
|
|
102
109
|
# 查看存储模式(此时应为稀疏模式)
|
|
103
110
|
|
|
104
|
-
print(repr(big_arr)) # 输出: BoolHybridArray(split_index=100,size=10000,is_sparse=True,small_len=
|
|
111
|
+
print(repr(big_arr)) # 输出: BoolHybridArray(split_index=100, size=10000, is_sparse=True, small_len=101, large_len=98)
|
|
105
112
|
|
|
106
113
|
# 自动优化存储
|
|
107
114
|
|
|
@@ -532,6 +539,12 @@ except OverflowError as e:
|
|
|
532
539
|
* **9.10.20**:优化性能,增加BHA_jit_log日志
|
|
533
540
|
* **9.10.21**:优化Ask_BHA,移除BHA_jit_log日志
|
|
534
541
|
* **9.10.22**:进一步优化Ask_BHA的性能
|
|
542
|
+
* **9.11.0**:新增对7.3.10以上版本的PyPy解释器的支持
|
|
543
|
+
* **9.11.1**:修复PyPy解释器下的保护机制过度保护bug
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
535
548
|
|
|
536
549
|
|
|
537
550
|
## **彩蛋:**
|
|
@@ -546,7 +559,11 @@ except OverflowError as e:
|
|
|
546
559
|
* A:BoolHybridArray是本库中的**核心类**,所有函数都是围绕他进行的,但需要`split_index`,`size`,`is_sparse`;
|
|
547
560
|
BoolHybridArr是一个**函数**,用于把一个可迭代对象转为`BoolHybridArray`类
|
|
548
561
|
* Q:为什么不建议把太大的本类型数组打印?
|
|
549
|
-
* A
|
|
562
|
+
* A:虽然BoolHybridArray类型数组省内存,但字符串不省内存,一个`True`要4字节,一个`False`要5字节,连逗号都要占1字节(`numpy.ndarray`:我都比字符串省内存)
|
|
563
|
+
- Q:为什么使用在Windows终端使用PyPy时建议先调用`chcp 65001`再启动PyPy?
|
|
564
|
+
* A:因为本库有很多的的中文报错和打印,项目里也可能会有。Windows终端里的PyPy默认是GBK编码,有中文时会乱码。chcp 65001可以切换到UTF-8编码,防止乱码。
|
|
565
|
+
|
|
566
|
+
|
|
550
567
|
|
|
551
568
|
## 源代码和原理
|
|
552
569
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
1
2
|
import sys
|
|
2
3
|
from types import ModuleType,FunctionType
|
|
3
4
|
from . import core
|
|
4
5
|
from .core import __builtins__,builtins
|
|
5
|
-
from . import int_array
|
|
6
|
-
|
|
6
|
+
try:from . import int_array
|
|
7
|
+
except:pass
|
|
8
|
+
__version__ = "9.11.1"
|
|
7
9
|
public_objects = []
|
|
8
10
|
for name in dir(core):
|
|
9
11
|
if not name.startswith("_"):
|
|
@@ -16,11 +18,11 @@ globals().update({
|
|
|
16
18
|
for name in public_objects
|
|
17
19
|
})
|
|
18
20
|
try:
|
|
19
|
-
__dict__ = ProtectedBuiltinsDict(globals())
|
|
20
|
-
sys.modules[__name__+'.int_array'] = ProtectedBuiltinsDict(int_array.__dict__)
|
|
21
|
-
sys.modules[__name__+'.core'] = ProtectedBuiltinsDict(core.__dict__)
|
|
22
21
|
sys.modules[__name__] = ProtectedBuiltinsDict(globals())
|
|
23
|
-
sys.modules[__name__].name =
|
|
22
|
+
sys.modules[__name__].name = __name__
|
|
23
|
+
sys.modules[__name__+'.core'] = ProtectedBuiltinsDict(core.__dict__,name = f'{__name__}.core')
|
|
24
|
+
__dict__ = ProtectedBuiltinsDict(globals())
|
|
25
|
+
sys.modules[__name__+'.int_array'] = ProtectedBuiltinsDict(int_array.__dict__,name = __name__+'.int_array')
|
|
24
26
|
core.__dict__ = ProtectedBuiltinsDict(core.__dict__)
|
|
25
27
|
except:
|
|
26
28
|
pass
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
import builtins
|
|
3
|
+
from types import MappingProxyType
|
|
3
4
|
import array,bisect,numpy as np
|
|
4
5
|
from collections.abc import MutableSequence,Iterable,Generator,Iterator,Sequence
|
|
5
6
|
import itertools,copy,sys,math,weakref,random,mmap,os
|
|
@@ -37,12 +38,23 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
|
|
|
37
38
|
super_cls.__setattr__('bases', bases)
|
|
38
39
|
super_cls.__setattr__('namespace', namespace)
|
|
39
40
|
super_cls.__setattr__('original_dict', dict(obj.__dict__))
|
|
40
|
-
del obj.original_dict["__abstractmethods__"]
|
|
41
|
-
|
|
41
|
+
try:del obj.original_dict["__abstractmethods__"]
|
|
42
|
+
except:pass
|
|
43
|
+
try:del obj.original_dict["_abc_impl"]
|
|
44
|
+
except:pass
|
|
45
|
+
try:del obj.original_dict['_abc_registry']
|
|
46
|
+
except:pass
|
|
47
|
+
try:del obj.original_dict['_abc_cache']
|
|
48
|
+
except:pass
|
|
49
|
+
try:del obj.original_dict['_abc_negative_cache']
|
|
50
|
+
except:pass
|
|
51
|
+
try:del obj.original_dict['_abc_negative_cache_version']
|
|
52
|
+
except:pass
|
|
53
|
+
super_cls.__setattr__('original_dict', MappingProxyType(obj.original_dict))
|
|
42
54
|
return obj
|
|
43
55
|
@lru_cache
|
|
44
56
|
def __str__(cls):
|
|
45
|
-
return
|
|
57
|
+
return f'{cls.__module__}.{cls.name}'
|
|
46
58
|
@lru_cache
|
|
47
59
|
def __repr__(cls,detailed = False):
|
|
48
60
|
if detailed:
|
|
@@ -87,6 +99,7 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
|
|
|
87
99
|
original_dict["__or__"] = __or__
|
|
88
100
|
except:
|
|
89
101
|
pass
|
|
102
|
+
original_dict = MappingProxyType(original_dict)
|
|
90
103
|
ResurrectMeta.__class__ = ResurrectMeta
|
|
91
104
|
class BHA_Function(metaclass=ResurrectMeta):
|
|
92
105
|
def __init__(self,v):
|
|
@@ -689,6 +702,9 @@ class BHA_List(list,metaclass=ResurrectMeta):
|
|
|
689
702
|
"对比numpy节省": f"{(1 - total / (temp + 96)) * 100:.6f}%"}
|
|
690
703
|
def __iter__(self):
|
|
691
704
|
return BHA_Iterator(super().__iter__())
|
|
705
|
+
def to_ascii_art(self, width=20):
|
|
706
|
+
art = '\n'.join([''.join(['■' if j else ' ' for j in i]) for i in self])
|
|
707
|
+
return '\n'.join(art)
|
|
692
708
|
class BHA_Iterator(Iterator,metaclass=ResurrectMeta):
|
|
693
709
|
__module__ = 'bool_hybrid_array'
|
|
694
710
|
def __init__(self,data):
|
|
@@ -711,11 +727,11 @@ class BHA_Iterator(Iterator,metaclass=ResurrectMeta):
|
|
|
711
727
|
return arr.copy() if copy else arr.view()
|
|
712
728
|
__rand__,__ror__,__rxor__ = __and__,__or__,__xor__
|
|
713
729
|
class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):
|
|
714
|
-
def __init__(self, *args, protected_names =
|
|
730
|
+
def __init__(self, *args, protected_names = ("T", "F", "BHA_Bool", "BHA_List", "BoolHybridArray", "BoolHybridArr",
|
|
715
731
|
"TruesArray", "FalsesArray", "ProtectedBuiltinsDict", "builtins",
|
|
716
732
|
"__builtins__", "__dict__","ResurrectMeta","math",
|
|
717
733
|
"np","protected_names","BHA_Function",
|
|
718
|
-
"__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt"
|
|
734
|
+
"__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt"),
|
|
719
735
|
name = 'builtins', **kwargs):
|
|
720
736
|
super().__init__(*args, **kwargs)
|
|
721
737
|
if name == 'builtins':
|
|
@@ -723,20 +739,27 @@ class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):
|
|
|
723
739
|
super().__setattr__('builtins',self)
|
|
724
740
|
super().__setattr__('__builtins__',self)
|
|
725
741
|
self.name = name
|
|
726
|
-
|
|
742
|
+
super().__setattr__("protected_names",protected_names)
|
|
727
743
|
def __setitem__(self, name, value):
|
|
728
|
-
if
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
744
|
+
if not hasattr(self,"protected_names"):
|
|
745
|
+
super().__setitem__(name, value)
|
|
746
|
+
return
|
|
747
|
+
try:
|
|
748
|
+
if name in ["T", "F"]:
|
|
749
|
+
current_T = self.get("T")
|
|
750
|
+
current_F = self.get("F")
|
|
751
|
+
if isinstance(current_T, BHA_bool) and isinstance(current_F, BHA_bool):
|
|
752
|
+
is_swap = (name == "T" and isinstance(value, BHA_bool) and value.value == current_F.value)or(name == "F" and isinstance(value, BHA_bool) and value.value == current_T.value)
|
|
753
|
+
if is_swap:
|
|
754
|
+
print(f"""警告:禁止交换内置常量 __{self.name}__["{name}"] 和 __builtins__["{'F' if name == 'T' else 'T'}"]!""")
|
|
755
|
+
raise AttributeError(f"""禁止交换内置常量 __{self.name}__["{name}"] 和 __{self.name}__["{'F' if name == 'T' else 'T'}"]""")
|
|
756
|
+
if name in self.protected_names and name not in ["T", "F"]:
|
|
757
|
+
print(f"警告:禁止修改内置常量 __{self.name}__['{name}']!")
|
|
758
|
+
raise AttributeError(f"禁止修改内置常量 __{self.name}__['{name}']")
|
|
759
|
+
except:
|
|
760
|
+
if sys.implementation.name == 'cpython':
|
|
761
|
+
raise
|
|
762
|
+
finally:super().__setitem__(name, value)
|
|
740
763
|
def __delitem__(self, name):
|
|
741
764
|
if name in self.protected_names:
|
|
742
765
|
print(f"警告:禁止删除内置常量 __builtins__['{name}']!")
|
|
@@ -749,10 +772,12 @@ class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):
|
|
|
749
772
|
else:
|
|
750
773
|
del self[name]
|
|
751
774
|
def __getattr__(self, name):
|
|
752
|
-
|
|
753
|
-
return
|
|
754
|
-
|
|
755
|
-
|
|
775
|
+
try:
|
|
776
|
+
return super().__getattribute__(name)
|
|
777
|
+
except AttributeError:
|
|
778
|
+
if name in self:
|
|
779
|
+
return self[name]
|
|
780
|
+
raise AttributeError(f"module 'builtins' has no attribute '{name}'") from None
|
|
756
781
|
def __setattr__(self,name,value):
|
|
757
782
|
try:protected = self.protected_names
|
|
758
783
|
except Exception:protected = self
|
{bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array/int_array/__init__.py
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
1
2
|
from __future__ import annotations
|
|
2
3
|
from ..core import *
|
|
3
4
|
import builtins
|
|
4
|
-
|
|
5
5
|
class IntBitTag(BHA_bool, metaclass=ResurrectMeta):
|
|
6
6
|
def __str__(self):
|
|
7
7
|
return "'-1'" if (hasattr(self, 'is_sign_bit') and self.is_sign_bit and self) else "'1'" if self else "'0'"
|
|
@@ -80,7 +80,7 @@ class IntHybridArray(BoolHybridArray):
|
|
|
80
80
|
block_end = block_start + self.bit_length
|
|
81
81
|
if block_end > self.size:
|
|
82
82
|
raise IndexError("索引超出范围")
|
|
83
|
-
bit_chunk = [super().__getitem__(j) for j in range(block_start, block_end)]
|
|
83
|
+
bit_chunk = [super(self.__class__, self).__getitem__(j) for j in range(block_start, block_end)]
|
|
84
84
|
num = self.to_int(bit_chunk)
|
|
85
85
|
result.append(num)
|
|
86
86
|
return IntHybridArray(result, self.bit_length)
|
|
@@ -91,7 +91,7 @@ class IntHybridArray(BoolHybridArray):
|
|
|
91
91
|
block_end = block_start + self.bit_length
|
|
92
92
|
if block_end > self.size:
|
|
93
93
|
raise IndexError("索引超出范围")
|
|
94
|
-
bit_chunk = [super().__getitem__(j) for j in range(block_start, block_end)]
|
|
94
|
+
bit_chunk = [super(self.__class__, self).__getitem__(j) for j in range(block_start, block_end)]
|
|
95
95
|
return self.to_int(bit_chunk)
|
|
96
96
|
|
|
97
97
|
def __setitem__(self, key, value):
|
|
@@ -145,14 +145,10 @@ class IntHybridArray(BoolHybridArray):
|
|
|
145
145
|
carry = 0 if num_bits[j] else 1
|
|
146
146
|
bool_data = [sign_bit] + num_bits
|
|
147
147
|
for bit_idx in range(self.bit_length):
|
|
148
|
-
super().__setitem__(block_start + bit_idx, bool_data[bit_idx])
|
|
148
|
+
super(self.__class__, self).__setitem__(block_start + bit_idx, bool_data[bit_idx])
|
|
149
149
|
|
|
150
150
|
def __iter__(self):
|
|
151
|
-
|
|
152
|
-
if i + self.bit_length > self.size:
|
|
153
|
-
break
|
|
154
|
-
bit_chunk = [super().__getitem__(j) for j in range(i, i + self.bit_length)]
|
|
155
|
-
yield self.to_int(bit_chunk)
|
|
151
|
+
return map(self.__getitem__,range(len(self)))
|
|
156
152
|
|
|
157
153
|
def __str__(self):
|
|
158
154
|
return f"IntHybridArray([{', '.join(map(str, self))}])"
|
|
@@ -173,7 +169,7 @@ class IntHybridArray(BoolHybridArray):
|
|
|
173
169
|
def index(self, value):
|
|
174
170
|
value = int(value)
|
|
175
171
|
x = f"{value} 不在 IntHybridArray 中"
|
|
176
|
-
for idx in range(len(self)+
|
|
172
|
+
for idx in range(len(self)+1>>1):
|
|
177
173
|
if self[idx] == value:
|
|
178
174
|
return idx
|
|
179
175
|
elif self[-idx] == value:
|
|
@@ -184,7 +180,7 @@ class IntHybridArray(BoolHybridArray):
|
|
|
184
180
|
def rindex(self, value):
|
|
185
181
|
value = int(value)
|
|
186
182
|
x = f"{value} 不在 IntHybridArray 中"
|
|
187
|
-
for idx in range(len(self)+
|
|
183
|
+
for idx in range(len(self)+1>>1):
|
|
188
184
|
if self[-idx] == value:
|
|
189
185
|
return -idx
|
|
190
186
|
elif self[idx] == value:
|
|
@@ -192,12 +188,7 @@ class IntHybridArray(BoolHybridArray):
|
|
|
192
188
|
if x != f"{value} 不在 IntHybridArray 中":
|
|
193
189
|
return x
|
|
194
190
|
raise ValueError(x)
|
|
195
|
-
def
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
else:
|
|
200
|
-
len_ = len(iterable)
|
|
201
|
-
self.total_bits += len_*self.bit_length
|
|
202
|
-
for i,j in zip(range(len_),iterable):
|
|
203
|
-
self[-i-1] = j
|
|
191
|
+
def append(self,v):
|
|
192
|
+
self.self.total_bits += self.bit_length
|
|
193
|
+
self[-1] = v
|
|
194
|
+
__all__ = list(globals())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bool-hybrid-array
|
|
3
|
-
Version: 9.
|
|
3
|
+
Version: 9.11.1
|
|
4
4
|
Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
|
|
5
5
|
Home-page: https://github.com/BKsell/bool-hybrid-array
|
|
6
6
|
Author: 蔡靖杰
|
|
@@ -17,6 +17,9 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
23
|
Classifier: License :: OSI Approved :: MIT License
|
|
21
24
|
Classifier: Operating System :: OS Independent
|
|
22
25
|
Requires-Python: >=3.8
|
|
@@ -24,6 +27,8 @@ Description-Content-Type: text/markdown
|
|
|
24
27
|
License-File: LICENSE
|
|
25
28
|
Requires-Dist: numpy>=1.19.0
|
|
26
29
|
Provides-Extra: int-array
|
|
30
|
+
Provides-Extra: numba-opt
|
|
31
|
+
Requires-Dist: numba>=0.55.0; extra == "numba-opt"
|
|
27
32
|
Dynamic: author
|
|
28
33
|
Dynamic: author-email
|
|
29
34
|
Dynamic: classifier
|
|
@@ -40,10 +45,17 @@ Dynamic: summary
|
|
|
40
45
|
|
|
41
46
|
# BoolHybridArray:高效的布尔混合数组库
|
|
42
47
|
|
|
48
|
+
<!-- 月下载量(核心推荐)+ 周下载量 + 总下载量 -->
|
|
49
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
50
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
51
|
+
[](https://pepy.tech/project/bool-hybrid-array)
|
|
52
|
+
|
|
43
53
|
一个专为布尔值优化的数组类,能够根据数据特征自动在密集存储和稀疏存储模式间切换,兼顾性能和内存效率。
|
|
44
54
|
|
|
45
55
|
## ***注:大版本号更新并非不兼容更新,而是重大更新***
|
|
46
56
|
|
|
57
|
+
注:当API完全稳定时就会发布版本规则较严谨的new-1.0.0版本,预期为10.x版本结束后
|
|
58
|
+
|
|
47
59
|
***注意:目前社区中若存在名称类似(如包含 “bool-hybrid-array”+ 后缀、boolean\_array、validate.io-boolean-array)的库,均与本项目(bool-hybrid-array)无关联,本项目的所有功能设计、代码实现均为独立开发;***
|
|
48
60
|
***其他平台里的类似名库绝不是我的库***
|
|
49
61
|
|
|
@@ -141,7 +153,7 @@ big_arr = BoolHybridArr([i % 100 == 0 for i in range(10000)])
|
|
|
141
153
|
|
|
142
154
|
# 查看存储模式(此时应为稀疏模式)
|
|
143
155
|
|
|
144
|
-
print(repr(big_arr)) # 输出: BoolHybridArray(split_index=100,size=10000,is_sparse=True,small_len=
|
|
156
|
+
print(repr(big_arr)) # 输出: BoolHybridArray(split_index=100, size=10000, is_sparse=True, small_len=101, large_len=98)
|
|
145
157
|
|
|
146
158
|
# 自动优化存储
|
|
147
159
|
|
|
@@ -572,6 +584,12 @@ except OverflowError as e:
|
|
|
572
584
|
* **9.10.20**:优化性能,增加BHA_jit_log日志
|
|
573
585
|
* **9.10.21**:优化Ask_BHA,移除BHA_jit_log日志
|
|
574
586
|
* **9.10.22**:进一步优化Ask_BHA的性能
|
|
587
|
+
* **9.11.0**:新增对7.3.10以上版本的PyPy解释器的支持
|
|
588
|
+
* **9.11.1**:修复PyPy解释器下的保护机制过度保护bug
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
575
593
|
|
|
576
594
|
|
|
577
595
|
## **彩蛋:**
|
|
@@ -586,7 +604,11 @@ except OverflowError as e:
|
|
|
586
604
|
* A:BoolHybridArray是本库中的**核心类**,所有函数都是围绕他进行的,但需要`split_index`,`size`,`is_sparse`;
|
|
587
605
|
BoolHybridArr是一个**函数**,用于把一个可迭代对象转为`BoolHybridArray`类
|
|
588
606
|
* Q:为什么不建议把太大的本类型数组打印?
|
|
589
|
-
* A
|
|
607
|
+
* A:虽然BoolHybridArray类型数组省内存,但字符串不省内存,一个`True`要4字节,一个`False`要5字节,连逗号都要占1字节(`numpy.ndarray`:我都比字符串省内存)
|
|
608
|
+
- Q:为什么使用在Windows终端使用PyPy时建议先调用`chcp 65001`再启动PyPy?
|
|
609
|
+
* A:因为本库有很多的的中文报错和打印,项目里也可能会有。Windows终端里的PyPy默认是GBK编码,有中文时会乱码。chcp 65001可以切换到UTF-8编码,防止乱码。
|
|
610
|
+
|
|
611
|
+
|
|
590
612
|
|
|
591
613
|
## 源代码和原理
|
|
592
614
|
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
from setuptools import setup, find_packages
|
|
2
|
-
import os
|
|
2
|
+
import os,sys
|
|
3
3
|
def get_long_description():
|
|
4
4
|
readme_path = os.path.join(os.path.dirname(__file__), 'README.md')
|
|
5
5
|
if os.path.exists(readme_path):
|
|
6
6
|
with open(readme_path, encoding='utf-8') as f:
|
|
7
7
|
return f.read()
|
|
8
8
|
return "一个高效的布尔数组(密集+稀疏混合存储,节省内存)"
|
|
9
|
+
if sys.implementation.name == "pypy":
|
|
10
|
+
if not hasattr(sys, "pypy_version_info") or sys.pypy_version_info[:3] < (7, 3, 10):
|
|
11
|
+
pypy_ver = ".".join(map(str, sys.pypy_version_info)) if hasattr(sys, "pypy_version_info") else "未知"
|
|
12
|
+
sys.exit(f"❌ 错误:bool-hybrid-array 要求 PyPy≥7.3.10,当前版本 {pypy_ver}")
|
|
9
13
|
setup(
|
|
10
14
|
name="bool-hybrid-array",
|
|
11
|
-
version="9.
|
|
15
|
+
version="9.11.1",
|
|
12
16
|
author="蔡靖杰",
|
|
13
|
-
extras_require={"int_array":[]},
|
|
17
|
+
extras_require={"int_array":[],"numba_opt": ["numba>=0.55.0"],},
|
|
14
18
|
author_email="1289270215@qq.com",
|
|
15
19
|
description="一个高效的布尔数组(密集+稀疏混合存储,节省内存)",
|
|
16
20
|
long_description=get_long_description(),
|
|
@@ -27,11 +31,14 @@ setup(
|
|
|
27
31
|
'Programming Language :: Python :: 3.12',
|
|
28
32
|
'Programming Language :: Python :: 3.13',
|
|
29
33
|
'Programming Language :: Python :: 3.14',
|
|
34
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
35
|
+
'Programming Language :: Python :: Implementation :: CPython',
|
|
36
|
+
'Programming Language :: Python :: Implementation :: PyPy',
|
|
30
37
|
"License :: OSI Approved :: MIT License",
|
|
31
38
|
"Operating System :: OS Independent",
|
|
32
39
|
],
|
|
33
40
|
keywords="boolean array, compact storage",
|
|
34
|
-
package_data={"": ["README.md", "LICENSE",'temp.py', 'temp.cmd','BHA_Opener.zip'],"bool_hybrid_array":["*"]},
|
|
41
|
+
package_data={"": ["README.md", "LICENSE",'temp.py', 'temp.cmd','BHA_Opener.zip'],"bool_hybrid_array":["*"],"bool_hybrid_array/__pycache__":['*.pyc']},
|
|
35
42
|
include_package_data=True,
|
|
36
43
|
url="https://github.com/BKsell/bool-hybrid-array",
|
|
37
44
|
project_urls={
|
|
File without changes
|
|
File without changes
|
{bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{bool_hybrid_array-9.10.22 → bool_hybrid_array-9.11.1}/bool_hybrid_array.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|