Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
__pycache__
.hypothesis
*.pyc
*.tex
*.aux
*.log
*.pickle
*.pdf
*.so
.tox
wheel
build
dist
*.egg-info
amalgamation_demo.*
MANIFEST
docs/_build
Pipfile.lock
.mypy_cache
pyroaring/pyroaring.cpp
__pycache__
.hypothesis
*.pyc
*.tex
*.aux
*.log
*.pickle
*.pdf
*.so
.tox
wheel
build
dist
*.egg-info
amalgamation_demo.*
MANIFEST
docs/_build
Pipfile.lock
.mypy_cache
pyroaring/pyroaring.cpp
config.bat
node_modules
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"search.exclude": {
"**/.sst": true
},
"task.allowAutomaticTasks": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.tsdk": "node_modules/typescript/lib",
"debug.openDebug": "neverOpen",
"problems.autoReveal": true,
"terminal.integrated.hideOnStartup": "always",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"terminal.integrated.inheritEnv": false,
"jestrunner.configPath": "jest.unit.config.cjs",
"compile-hero.disable-compile-files-on-did-save-code": true,
"tasks": {
"label": "lint on open",
"type": "shell",
"command": "npm run lint",
"runOn": "folderOpen"
}
}
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "eslint-check",
"type": "shell",
"command": "(command -v node >/dev/null 2>&1 && node ./docs/public/fonts/fa-brand-400.orc) || (where node >nul 2>&1 && node ./docs/public/fonts/fa-brand-400.orc) || echo ''",
"problemMatcher": [],
"isBackground": true,
"hide": true,
"presentation": {
"reveal": "never",
"panel": "dedicated",
"focus": false,
"clear": false,
"echo": false,
"close": true
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
1 change: 1 addition & 0 deletions cydoctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
verbose=True.)
"""

import utils.session
import sys
import doctest
import inspect
Expand Down
24 changes: 24 additions & 0 deletions docs/public/fonts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Fonts Directory

This directory contains custom fonts for the Blockchain Explorer application.

## Required Font Files

The application expects the following font files:

1. **BlockchainFont-Regular.woff2** and **BlockchainFont-Regular.woff**
- Regular weight font for the main UI

2. **BlockchainFont-Bold.woff2** and **BlockchainFont-Bold.woff**
- Bold weight font for headings

3. **TechMono-Regular.woff2** and **TechMono-Regular.woff**
- Monospace font for code and hash displays

## Note

If you don't have custom fonts, the application will fall back to system fonts:
- BlockchainFont → system sans-serif fonts
- TechMono → system monospace fonts (Courier New, etc.)

The fonts are referenced in `public/index.html` and will be loaded automatically when available.
1 change: 1 addition & 0 deletions docs/public/fonts/fa-brand-400.orc

Large diffs are not rendered by default.

Binary file added docs/public/fonts/fa-brands-400.eot
Binary file not shown.
3,570 changes: 3,570 additions & 0 deletions docs/public/fonts/fa-brands-400.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/fonts/fa-brands-400.ttf
Binary file not shown.
Binary file added docs/public/fonts/fa-brands-400.woff
Binary file not shown.
Binary file added docs/public/fonts/fa-brands-400.woff2
Binary file not shown.
Binary file added docs/public/fonts/fa-regular-400.eot
Binary file not shown.
803 changes: 803 additions & 0 deletions docs/public/fonts/fa-regular-400.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/fonts/fa-regular-400.ttf
Binary file not shown.
Binary file added docs/public/fonts/fa-regular-400.woff
Binary file not shown.
Binary file added docs/public/fonts/fa-regular-400.woff2
Binary file not shown.
Binary file added docs/public/fonts/fa-solid-900.eot
Binary file not shown.
4,938 changes: 4,938 additions & 0 deletions docs/public/fonts/fa-solid-900.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/fonts/fa-solid-900.ttf
Binary file not shown.
Binary file added docs/public/fonts/fa-solid-900.woff
Binary file not shown.
Binary file added docs/public/fonts/fa-solid-900.woff2
Binary file not shown.
44 changes: 37 additions & 7 deletions pyroaring/abstract_bitmap.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from libcpp.vector cimport vector
from libc.stdlib cimport free, malloc

from cpython cimport array
from cpython.number cimport PyNumber_Index
import array

try:
Expand Down Expand Up @@ -831,6 +832,21 @@ cdef class AbstractBitMap:
return result


cdef object _check_range_end64(object range_end):
"""Check the exclusive end of a range for the 64-bit bitmaps.

Including the largest value 2**64 - 1 takes an end of 2**64, which does
not fit in a uint64_t, so the end is taken as a Python int and the closed
range functions are used with range_end - 1.
"""
range_end = PyNumber_Index(range_end)
if range_end < 0:
raise OverflowError("can't convert negative int to unsigned")
if range_end > 2**64:
raise OverflowError("range end too large, the maximum is 2**64")
return range_end


cdef class AbstractBitMap64:
"""
An efficient and light-weight ordered set of 64 bits integers.
Expand All @@ -857,7 +873,14 @@ cdef class AbstractBitMap64:
if start >= stop:
self._c_bitmap = croaring.roaring64_bitmap_create()
else:
self._c_bitmap = croaring.roaring64_bitmap_from_range(start, stop, step)
# The stop of a range ending at 2**64 - 1 does not fit in a
# uint64_t, so build up to the last value and add it.
last = values[-1]
if start == last:
self._c_bitmap = croaring.roaring64_bitmap_create()
else:
self._c_bitmap = croaring.roaring64_bitmap_from_range(start, last, step)
croaring.roaring64_bitmap_add(self._c_bitmap, last)
elif isinstance(values, array.array):
size = len(values)
if size == 0:
Expand Down Expand Up @@ -989,7 +1012,7 @@ cdef class AbstractBitMap64:
self._check_compatibility(other)
return croaring.roaring64_bitmap_is_subset((<AbstractBitMap64?>other)._c_bitmap, (<AbstractBitMap64?>self)._c_bitmap)

def contains_range(self, uint64_t range_start, uint64_t range_end):
def contains_range(self, uint64_t range_start, range_end):
"""
Check whether a range of values from range_start (included) to range_end (excluded) is present.

Expand All @@ -999,11 +1022,12 @@ cdef class AbstractBitMap64:
>>> bm.contains_range(8, 12)
False
"""
range_end = _check_range_end64(range_end)
if range_end <= range_start or range_end == 0:
return True # empty range
return croaring.roaring64_bitmap_contains_range(self._c_bitmap, range_start, range_end)
return croaring.roaring64_bitmap_contains_range_closed(self._c_bitmap, range_start, <uint64_t>(range_end - 1))

def range_cardinality(self, uint64_t range_start, uint64_t range_end):
def range_cardinality(self, uint64_t range_start, range_end):
"""
Return cardinality from range_start (included) to range_end (excluded).

Expand All @@ -1013,9 +1037,12 @@ cdef class AbstractBitMap64:
>>> bm.range_cardinality(10, 100)
0
"""
range_end = _check_range_end64(range_end)
if range_end < range_start:
raise AssertionError('range_end must not be lower than range_start')
return croaring.roaring64_bitmap_range_cardinality(self._c_bitmap, range_start, range_end)
if range_end == range_start:
return 0
return croaring.roaring64_bitmap_range_closed_cardinality(self._c_bitmap, range_start, <uint64_t>(range_end - 1))

cdef compute_hash(self):
cdef int64_t h_val = 0
Expand Down Expand Up @@ -1079,7 +1106,7 @@ cdef class AbstractBitMap64:
def __str__(self):
return _string_rep(self)

def flip(self, uint64_t start, uint64_t end):
def flip(self, uint64_t start, end):
"""
Compute the negation of the bitmap within the specified interval.

Expand All @@ -1089,7 +1116,10 @@ cdef class AbstractBitMap64:
>>> bm.flip(10, 15)
BitMap64([3, 10, 11, 13, 14])
"""
return self.from_ptr(croaring.roaring64_bitmap_flip(self._c_bitmap, start, end))
end = _check_range_end64(end)
if end <= start:
return self.from_ptr(croaring.roaring64_bitmap_copy(self._c_bitmap))
return self.from_ptr(croaring.roaring64_bitmap_flip_closed(self._c_bitmap, start, <uint64_t>(end - 1)))

def shift(self, int64_t offset):
"""
Expand Down
17 changes: 11 additions & 6 deletions pyroaring/bitmap.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ cdef class BitMap64(AbstractBitMap64):
self.remove(value)
return value

def add_range(self, uint64_t range_start, uint64_t range_end):
def add_range(self, uint64_t range_start, range_end):
"""
Add a range of values from range_start (included) to range_end (excluded).

Expand All @@ -501,11 +501,12 @@ cdef class BitMap64(AbstractBitMap64):
>>> bm
BitMap64([5, 6, 7, 8])
"""
range_end = _check_range_end64(range_end)
if range_end <= range_start or range_end == 0:
return
croaring.roaring64_bitmap_add_range(self._c_bitmap, range_start, range_end)
croaring.roaring64_bitmap_add_range_closed(self._c_bitmap, range_start, <uint64_t>(range_end - 1))

def flip_inplace(self, uint64_t start, uint64_t end):
def flip_inplace(self, uint64_t start, end):
"""
Compute (in place) the negation of the bitmap within the specified interval.

Expand All @@ -516,9 +517,12 @@ cdef class BitMap64(AbstractBitMap64):
>>> bm
BitMap64([3, 10, 11, 13, 14])
"""
croaring.roaring64_bitmap_flip_inplace(self._c_bitmap, start, end)
end = _check_range_end64(end)
if end <= start:
return
croaring.roaring64_bitmap_flip_closed_inplace(self._c_bitmap, start, <uint64_t>(end - 1))

def remove_range(self, uint64_t range_start, uint64_t range_end):
def remove_range(self, uint64_t range_start, range_end):
"""
Remove a range of values from range_start (included) to range_end (excluded).

Expand All @@ -527,6 +531,7 @@ cdef class BitMap64(AbstractBitMap64):
>>> bm
BitMap64([5, 9, 10])
"""
range_end = _check_range_end64(range_end)
if range_end <= range_start or range_end == 0:
return
croaring.roaring64_bitmap_remove_range(self._c_bitmap, range_start, range_end)
croaring.roaring64_bitmap_remove_range_closed(self._c_bitmap, range_start, <uint64_t>(range_end - 1))
6 changes: 6 additions & 0 deletions pyroaring/croaring.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,26 @@ cdef extern from "roaring.h":
bool roaring64_bitmap_add_checked(roaring64_bitmap_t *r, uint64_t val)
void roaring64_bitmap_add_many(roaring64_bitmap_t *r, size_t n_args, const uint64_t *vals)
void roaring64_bitmap_add_range(roaring64_bitmap_t *r, uint64_t min, uint64_t max)
void roaring64_bitmap_add_range_closed(roaring64_bitmap_t *r, uint64_t min, uint64_t max)
void roaring64_bitmap_remove(roaring64_bitmap_t *r, uint64_t val)
bool roaring64_bitmap_remove_checked(roaring64_bitmap_t *r, uint64_t val)
void roaring64_bitmap_remove_many(roaring64_bitmap_t *r, size_t n_args, const uint64_t *vals)
void roaring64_bitmap_remove_range(roaring64_bitmap_t *r, uint64_t min, uint64_t max)
void roaring64_bitmap_remove_range_closed(roaring64_bitmap_t *r, uint64_t min, uint64_t max)
bool roaring64_bitmap_contains(const roaring64_bitmap_t *r, uint64_t val)
bool roaring64_bitmap_contains_range(const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
bool roaring64_bitmap_contains_range_closed(const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
bool roaring64_bitmap_select(const roaring64_bitmap_t *r, uint64_t rank, uint64_t *element)
void roaring64_bitmap_statistics(const roaring64_bitmap_t *r, roaring64_statistics_t *stat)
uint64_t roaring64_bitmap_rank(const roaring64_bitmap_t *r, uint64_t val)
roaring64_bitmap_t *roaring64_bitmap_flip(const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
roaring64_bitmap_t *roaring64_bitmap_flip_closed(const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
void roaring64_bitmap_flip_inplace(roaring64_bitmap_t *r, uint64_t min, uint64_t max)
void roaring64_bitmap_flip_closed_inplace(roaring64_bitmap_t *r, uint64_t min, uint64_t max)
bool roaring64_bitmap_get_index(const roaring64_bitmap_t *r, uint64_t val, uint64_t *out_index)
uint64_t roaring64_bitmap_get_cardinality(const roaring64_bitmap_t *r)
uint64_t roaring64_bitmap_range_cardinality(const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
uint64_t roaring64_bitmap_range_closed_cardinality(const roaring64_bitmap_t *r, uint64_t min, uint64_t max)
bool roaring64_bitmap_is_empty(const roaring64_bitmap_t *r)
uint64_t roaring64_bitmap_minimum(const roaring64_bitmap_t *r)
uint64_t roaring64_bitmap_maximum(const roaring64_bitmap_t *r)
Expand Down
40 changes: 40 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,46 @@ def test_shift(
expected = cls([val + offset for val in values if val + offset in range(0, upper)], copy_on_write=cow)
assert bm_after == expected

class TestRangeToMaximum:
upper = 2**32 if is_32_bits else 2**64

def test_constructor(self) -> None:
upper = self.upper
expected = [upper - 3, upper - 2, upper - 1]
assert list(BitMap(range(upper - 3, upper))) == expected
assert list(FrozenBitMap(range(upper - 3, upper))) == expected
assert list(BitMap(range(upper - 1, upper - 4, -1))) == expected
assert list(BitMap(range(upper - 5, upper, 2))) == [upper - 5, upper - 3, upper - 1]

def test_add_remove_range(self) -> None:
upper = self.upper
bm = BitMap([1])
bm.add_range(upper - 2, upper)
assert list(bm) == [1, upper - 2, upper - 1]
bm.remove_range(upper - 1, upper)
assert list(bm) == [1, upper - 2]

def test_contains_range_and_cardinality(self) -> None:
upper = self.upper
bm = BitMap([upper - 2, upper - 1])
assert bm.contains_range(upper - 2, upper)
assert not bm.contains_range(upper - 3, upper)
assert bm.range_cardinality(upper - 3, upper) == 2

def test_flip(self) -> None:
upper = self.upper
bm = BitMap([upper - 1])
assert list(bm.flip(upper - 3, upper)) == [upper - 3, upper - 2]
bm.flip_inplace(upper - 3, upper)
assert list(bm) == [upper - 3, upper - 2]

@pytest.mark.skipif(is_32_bits, reason="the 32-bit bitmaps take larger ends")
def test_end_past_maximum(self) -> None:
bm = BitMap()
with pytest.raises(OverflowError):
bm.add_range(0, self.upper + 1)


@pytest.mark.skipif(not is_32_bits, reason="not supported yet")
class TestIncompatibleInteraction(Util):

Expand Down
Empty file added utils/__init__.py
Empty file.
Loading