基于咆哮位图的压缩整数集。
croaring的Python项目详细描述
Roaring bitmaps快速,压缩, 和便携式位图,用于存储唯一排序的整数集。这些 位图提供了比现实世界更好的空间复杂度和性能。 典型的散列集(例如python的内置set),可以是 序列化为可移植格式,以便存储和与 C/C++、Java和GO库。
这个图书馆使 CRoaring实现 在Python2.7和3.5+中提供。它使用 CFFI,所以它对两个都有效 cpython和pypy。实现了完整的python set接口。 包括全面测试。
安装
pip install croaring
croaring源代码包含在python库中,因此 需要从其他地方安装它(尽管您可能需要一个C编译器 如果二进制软件包不适用于您的体系结构,则可用。
用法
实例化一个croaring.RoaringBitmap(),并像 正常set:
>>> import croaring >>> bitmap = croaring.RoaringBitmap() >>> bitmap RoaringBitmap([]) >>> bitmap.add(1) >>> bitmap.add(4572) >>> bitmap.add(326) >>> bitmap RoaringBitmap([1, 326, 4572])
您可以使用二进制运算符(|、&、^和-)或 他们的英文名字(union,intersection, symmetric_difference和difference):
>>> bitmap | RoaringBitmap([50, 95]) RoaringBitmap([1, 50, 95, 326, 4572]) >>> bitmap & RoaringBitmap([200, 326]) RoaringBitmap([326]) >>> bitmap ^ RoaringBitmap([200, 326]) RoaringBitmap([1, 200, 4572])由于位图是有序的,索引(包括负)是 支持:
>>> bitmap[1] 326 >>> bitmap[-1] 4572
最后,您可以从一个范围构造一个位图,类似于 python内置的参数range:
>>> RoaringBitmap.range(10) RoaringBitmap([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> RoaringBitmap.range(2, 10) RoaringBitmap([2, 3, 4, 5, 6, 7, 8, 9]) >>> RoaringBitmap.range(2, 10, 3) RoaringBitmap([2, 5, 8])
许可证
Croaring是根据Apache许可证v2.0获得许可的:
Copyright 2016 The CRoaring authors
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
所有其他代码在未经许可的情况下发布:
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org/