You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-37Lines changed: 84 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# Containers-Buffer
2
-
A Circular Buffer implementation providing efficient temporary storage with fixed capacity and automatic wraparound functionality.
2
+
A Circular Buffer implementation providing efficient temporary storage with fixed capacity and automatic wraparound functionality. Available in both FIFO (First In, First Out) and LIFO (Last In, First Out) variants.
@@ -8,6 +8,30 @@ A Circular Buffer implementation providing efficient temporary storage with fixe
8
8
9
9
A Buffer (also known as a circular buffer or ring buffer) is a data structure that uses a fixed-size array as if it were connected end-to-end. It provides efficient insertion and removal operations with constant time complexity O(1). When the buffer reaches its maximum capacity, new elements overwrite the oldest ones, making it perfect for streaming data and producer-consumer scenarios.
10
10
11
+
### We provide two types of buffers:
12
+
- FIFO Buffer - First In, First Out (Queue behavior)
13
+
- LIFO Buffer - Last In, First Out (Stack behavior)
14
+
15
+
## Loading
16
+
The following script installs Containers-Buffer in Pharo.
Buffers solve a critical problem in modern applications: **handling continuous data streams safely**. Perfect for keeping "recent N items" automatically without memory bloat or performance degradation.
13
37
@@ -16,35 +40,81 @@ Buffers solve a critical problem in modern applications: **handling continuous d
16
40
-**O(1) Performance**: Lightning-fast operations regardless of data volume
17
41
-**Zero Memory Leaks**: Automatic cleanup of old data
18
42
-**Streaming Optimized**: Designed for continuous data flow
43
+
-**Flexible Ordering**: Choose FIFO or LIFO based on your needs
44
+
45
+
46
+
## FIFO Buffer Use Cases
19
47
20
48
### Chat Applications
49
+
This example demonstrates how to use a FIFO buffer to maintain a chat history, automatically removing the oldest messages when new ones are added.
50
+
21
51
```smalltalk
22
52
"Chat room - keep last 50 messages automatically"
23
-
chat := CTBuffer withCapacity: 50.
53
+
chat := CTFIFOBuffer withCapacity: 50.
24
54
25
-
chat put: 'User1: Hello everyone!'.
26
-
chat put: 'User2: How are you doing?'.
55
+
chat push: 'User1: Hello everyone!'.
56
+
chat push: 'User2: How are you doing?'.
27
57
28
58
"... more messages flow in ..."
29
-
chat put: 'User3: Good morning!'. "Oldest message automatically removed"
59
+
chat push: 'User3: Good morning!'. "Oldest message automatically removed"
30
60
31
61
"Always has recent 50 messages, zero manual cleanup"
32
62
```
33
63
34
64
### File Processing in Chunks
65
+
This example shows how to process large files in manageable chunks without loading the entire file into memory, using a FIFO buffer to handle data efficiently.
66
+
35
67
```smalltalk
36
68
"Process massive files without loading everything into memory"
undoBuffer push: lastAction. "Puts 'Add italic formatting' back on top"
97
+
"Now 'Add italic formatting' is on top, ready to be undone next"
98
+
```
99
+
100
+
### Browser History
101
+
This example demonstrates how to implement a simple browser history using a LIFO buffer, allowing users to navigate back through their most recent pages.
102
+
103
+
```smalltalk
104
+
"Browser back button - show most recent pages first"
0 commit comments