From f0a88d9e7296a6bdc5ab3a0a399b5e1a370fca89 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 6 Jul 2024 23:36:02 +0100 Subject: [PATCH] posts: gap-buffer: add accessors --- content/posts/2024-07-06-gap-buffer/index.md | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/content/posts/2024-07-06-gap-buffer/index.md b/content/posts/2024-07-06-gap-buffer/index.md index 311ba62..87dd315 100644 --- a/content/posts/2024-07-06-gap-buffer/index.md +++ b/content/posts/2024-07-06-gap-buffer/index.md @@ -71,3 +71,30 @@ class GapBuffer: self._gap_start = 0 self._gap_end = initial_capacity ``` + +### Accessors + +I'm mostly adding these for exposition, and making it easier to write `assert`s +later. + +```python +@property +def capacity(self) -> int: + return len(self._buf) + +@property +def gap_length(self) -> int: + return self._gap_end - self._gap_start + +@property +def string_length(self) -> int: + return self.capacity - self.gap_length + +@property +def prefix_length(self) -> int: + return self._gap_start + +@property +def suffix_length(self) -> int: + return self.capacity - self._gap_end +```