Skip to content

Commit

Permalink
Memory.blocks() using memoryviews only
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Zoppi <[email protected]>
  • Loading branch information
TexZK committed Jan 21, 2024
1 parent 3518227 commit ad3af59
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

0.0.8 (2024-01-21)
------------------

* Added ``chop`` method.
* Minor fixes.


0.0.7 (2023-12-10)
------------------

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2020-2023, Andrea Zoppi
Copyright (c) 2020-2024, Andrea Zoppi
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
4 changes: 2 additions & 2 deletions src/bytesparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Andrea Zoppi.
# Copyright (c) 2020-2024, Andrea Zoppi.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -112,7 +112,7 @@
"""

__version__ = '0.0.7'
__version__ = '0.0.8'

from .inplace import Memory
from .inplace import bytesparse
Expand Down
4 changes: 2 additions & 2 deletions src/bytesparse/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Andrea Zoppi.
# Copyright (c) 2020-2024, Andrea Zoppi.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -703,7 +703,7 @@ def blocks(
self,
start: Optional[Address] = None,
endex: Optional[Address] = None,
) -> Iterator[Tuple[Address, memoryview]]:
) -> Iterator[Block]:
r"""Iterates over blocks.
Iterates over data blocks within an address range.
Expand Down
13 changes: 7 additions & 6 deletions src/bytesparse/inplace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Andrea Zoppi.
# Copyright (c) 2020-2024, Andrea Zoppi.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -856,12 +856,13 @@ def blocks(
self,
start: Optional[Address] = None,
endex: Optional[Address] = None,
) -> Iterator[Tuple[Address, Union[memoryview, bytearray]]]:
) -> Iterator[Block]:

blocks = self._blocks
if blocks:
if start is None and endex is None: # faster
yield from blocks
for block_start, block_data in blocks:
yield [block_start, memoryview(block_data)]
else:
block_index_start = 0 if start is None else self._block_index_start(start)
block_index_endex = len(blocks) if endex is None else self._block_index_endex(endex)
Expand All @@ -875,7 +876,7 @@ def blocks(
if slice_start < slice_endex:
slice_view = memoryview(block_data)
slice_view = slice_view[(slice_start - block_start):(slice_endex - block_start)]
yield slice_start, slice_view
yield [slice_start, slice_view]

def bound(
self,
Expand Down Expand Up @@ -993,7 +994,7 @@ def chop(
start: Optional[Address] = None,
endex: Optional[Address] = None,
align: bool = False,
) -> Iterator[Block]:
) -> Iterator[Tuple[Address, memoryview]]:

if width < 1:
raise ValueError('invalid width')
Expand Down Expand Up @@ -3091,7 +3092,7 @@ def blocks(
self,
start: Optional[Address] = None,
endex: Optional[Address] = None,
) -> Iterator[Tuple[Address, memoryview]]:
) -> Iterator[Block]:

start, endex = self._rectify_span(start, endex)
yield from super().blocks(start=start, endex=endex)
Expand Down
2 changes: 1 addition & 1 deletion src/bytesparse/io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Andrea Zoppi.
# Copyright (c) 2020-2024, Andrea Zoppi.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion tests/_common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Andrea Zoppi.
# Copyright (c) 2020-2024, Andrea Zoppi.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inplace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Andrea Zoppi.
# Copyright (c) 2020-2024, Andrea Zoppi.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Andrea Zoppi.
# Copyright (c) 2020-2024, Andrea Zoppi.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down

0 comments on commit ad3af59

Please sign in to comment.