@@ -16,11 +16,21 @@ Class {
1616}
1717
1818{ #category : ' instance creation' }
19- CTAbstractBuffer class >> withCapacity: anInteger [
19+ CTAbstractBuffer class >> new [
20+
21+ " Create a new buffer with default capacity"
22+
23+ ^ self new : 10
24+ ]
25+
26+ { #category : ' instance creation' }
27+ CTAbstractBuffer class >> new : anInteger [
28+
29+ " Create a new buffer with the specified capacity"
2030
2131 anInteger < 1 ifTrue: [ self error: ' Capacity must be positive' ].
22- ^ self new
23- capacity : anInteger;
32+ ^ self basicNew
33+ initializeWithCapacity : anInteger;
2434 yourself
2535]
2636
@@ -40,24 +50,6 @@ CTAbstractBuffer >> capacity [
4050 ^ capacity
4151]
4252
43- { #category : ' accessing' }
44- CTAbstractBuffer >> capacity: anInteger [
45-
46- capacity := anInteger.
47- elements := Array new : capacity
48- ]
49-
50- { #category : ' actions' }
51- CTAbstractBuffer >> clear [
52-
53- " Remove all elements from the buffer"
54-
55- 1 to: capacity do: [ :i | elements at: i put: nil ].
56- readIndex := 1 .
57- writeIndex := 1 .
58- currentSize := 0
59- ]
60-
6153{ #category : ' copying' }
6254CTAbstractBuffer >> copy [
6355
@@ -80,7 +72,13 @@ CTAbstractBuffer >> elements [
8072CTAbstractBuffer >> initialize [
8173
8274 super initialize.
83- capacity := 10 .
75+ self initializeWithCapacity: 10
76+ ]
77+
78+ { #category : ' private' }
79+ CTAbstractBuffer >> initializeWithCapacity: anInteger [
80+
81+ capacity := anInteger.
8482 elements := Array new : capacity.
8583 readIndex := 1 .
8684 writeIndex := 1 .
@@ -130,7 +128,7 @@ CTAbstractBuffer >> pop [
130128 ^ element
131129]
132130
133- { #category : ' testing ' }
131+ { #category : ' adding ' }
134132CTAbstractBuffer >> push: anObject [
135133 " Add an element to the buffer"
136134
@@ -159,7 +157,7 @@ CTAbstractBuffer >> push: anObject [
159157 ^ anObject
160158]
161159
162- { #category : ' testing ' }
160+ { #category : ' adding ' }
163161CTAbstractBuffer >> pushAll: aCollection [
164162
165163 aCollection do: [ :e | self push: e ].
@@ -173,6 +171,17 @@ CTAbstractBuffer >> readIndex [
173171 ^ readIndex
174172]
175173
174+ { #category : ' removing' }
175+ CTAbstractBuffer >> removeAll [
176+
177+ " Remove all elements from the buffer"
178+
179+ 1 to: capacity do: [ :i | elements at: i put: nil ].
180+ readIndex := 1 .
181+ writeIndex := 1 .
182+ currentSize := 0
183+ ]
184+
176185{ #category : ' accessing' }
177186CTAbstractBuffer >> size [
178187
0 commit comments