X Tutup
Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
adding
accessing
add: anAssociation
self privateAt: anAssociation key put: anAssociation value.
^ anAssociation
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
adding
"protocol: adding"
addAll: aDictionary
aDictionary keysAndValuesDo: [ :key :value |
self privateAt: key put: value ].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
accessing
allAt: aKey
^ self privateAllAt: aKey startingAt: 1
^ Array streamContents: [ :stream |
1 to: size do: [ :index |
(keys at: index) = aKey
ifTrue: [ stream nextPut: (values at: index) ] ] ]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
adding
accessing
at: aKey add: aValue
"Add an association between aKey and aValue. Do not replace existing
values with the same key."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ enumerating
keysAndAllValuesDo: aTwoArgumentBlock
| seenKeys |
seenKeys := GRSmallOrderedSet new.
1 to: size * 2 - 1 by: 2 do: [ :index |
1 to: size do: [ :index |
| key |
key := table at: index.
key := keys at: index.
(seenKeys includes: key) ifFalse: [
aTwoArgumentBlock
value: key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
private
privateAllAt: aKey startingAt: index
private
privateAllAt: aKey startingAt: aStartInteger
^ Array new: 2 streamContents: [ :stream |
index to: size * 2 - 1 by: 2 do: [ :i |
(table at: i) = aKey
ifTrue: [ stream nextPut: (table at: i + 1) ] ] ]
aStartInteger to: size do: [ :index |
(keys at: index) = aKey
ifTrue: [ stream nextPut: (values at: index) ] ] ]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
removing
accessing
removeKey: aKey ifAbsent: aBlock
"Remove aKey from the receiver, evaluate aBlock if the element is missing."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
},
"instance" : {
"add:" : "lr 7/25/2011 19:52",
"addAll:" : "pmm 8/25/2016 12:32",
"allAt:" : "pmm 8/25/2016 15:09",
"addAll:" : "pmm 8/26/2016 15:57",
"allAt:" : "jf 2/15/2010 15:39",
"allAt:ifAbsent:" : "jf 2/15/2010 15:39",
"at:add:" : "jf 2/15/2010 13:24",
"keysAndAllValuesDo:" : "pmm 8/25/2016 15:12",
"privateAllAt:startingAt:" : "pmm 8/25/2016 15:08",
"removeKey:ifAbsent:" : "pmm 8/22/2016 12:10" } }
"keysAndAllValuesDo:" : "pmm 8/26/2016 15:52",
"privateAllAt:startingAt:" : "pmm 8/26/2016 15:52",
"removeKey:ifAbsent:" : "pmm 8/26/2016 15:56" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am an implementation of an ordered multi-map. I allow multiple values to be associated with the same key and maintain the order of addition. #at: and its derivatives all operate on the first matching key, while #allAt: returns the complete list of values for a key in the order they were added.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
adding
add: anAssociation
self privateAt: anAssociation key put: anAssociation value.
^ anAssociation
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
adding
addAll: aDictionary
aDictionary keysAndValuesDo: [ :key :value |
self privateAt: key put: value ].
^ aDictionary
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
allAt: aKey
^ self privateAllAt: aKey startingAt: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
allAt: aKey ifAbsent: absentBlock
| results |
results := self allAt: aKey.
^ results isEmpty
ifTrue: [ absentBlock value ]
ifFalse: [ results ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
adding
at: aKey add: aValue
"Add an association between aKey and aValue. Do not replace existing
values with the same key."

^ self privateAt: aKey put: aValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
enumerating
keysAndAllValuesDo: aTwoArgumentBlock
| seenKeys |
seenKeys := GRSmallOrderedSet new.
1 to: size * 2 - 1 by: 2 do: [ :index |
| key |
key := table at: index.
(seenKeys includes: key) ifFalse: [
aTwoArgumentBlock
value: key
value: (self privateAllAt: key startingAt: index).
seenKeys add: key ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
private
privateAllAt: aKey startingAt: index
^ Array new: 2 streamContents: [ :stream |
index to: size * 2 - 1 by: 2 do: [ :i |
(table at: i) = aKey
ifTrue: [ stream nextPut: (table at: i + 1) ] ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
removing
removeKey: aKey ifAbsent: aBlock
"Remove aKey from the receiver, evaluate aBlock if the element is missing."

"This is inefficient and could be optimized."
| removed |
removed := Array new: 2 streamContents: [ :stream |
| index |
[ (index := self findIndexFor: aKey) = 0 ] whileFalse: [
stream nextPut: (self removeIndex: index) ] ].
^ removed isEmpty
ifTrue: [ aBlock value ]
ifFalse: [ removed ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"class" : {
},
"instance" : {
"add:" : "lr 7/25/2011 19:52",
"addAll:" : "pmm 8/25/2016 12:32",
"allAt:" : "pmm 8/25/2016 15:09",
"allAt:ifAbsent:" : "jf 2/15/2010 15:39",
"at:add:" : "jf 2/15/2010 13:24",
"keysAndAllValuesDo:" : "pmm 8/25/2016 15:12",
"privateAllAt:startingAt:" : "pmm 8/25/2016 15:08",
"removeKey:ifAbsent:" : "pmm 8/22/2016 12:10" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "Grease-Core-Collections",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "jf 2/15/2010 16:04",
"instvars" : [
],
"name" : "GROrderedMultiMap2",
"pools" : [
],
"super" : "GRSmallDictionary2",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -1 +1 @@
I am an implementation of a dictionary. Compared to other dictionaries I am very efficient for small sizes, speed- and space-wise. I also mantain the order in which elements are added when iterating. My implementation features some ideas from the RefactoringBrowser and others from Eclipse Collections.
I am an implementation of a dictionary. Compared to other dictionaries I am very efficient for small sizes, speed- and space-wise. I also mantain the order in which elements are added when iterating. My implementation features some ideas from the RefactoringBrowser.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
adding
accessing
add: anAssociation
self at: anAssociation key put: anAssociation value.
^ anAssociation
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ at: aKey ifAbsent: aBlock
| index |
index := self findIndexFor: aKey.
^ index = 0
ifFalse: [ table at: index + 1 ]
ifFalse: [ values at: index ]
ifTrue: [ aBlock value ]
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ at: aKey ifAbsentPut: aBlock
| index |
index := self findIndexFor: aKey.
^ index = 0
ifFalse: [ table at: index + 1 ]
ifFalse: [ values at: index ]
ifTrue: [ self privateAt: aKey put: aBlock value ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ at: aKey ifPresent: aBlock

| index |
index := self findIndexFor: aKey.
^ index = 0 ifFalse: [ aBlock value: (table at: index + 1) ]
^ index = 0 ifFalse: [ aBlock value: (values at: index) ]
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ at: aKey put: aValue
| index |
index := self findIndexFor: aKey.
^ index = 0
ifFalse: [ table at: index + 1 put: aValue ]
ifFalse: [ values at: index put: aValue ]
ifTrue: [ self privateAt: aKey put: aValue ]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enumerating
do: aBlock
2 to: size * 2 by: 2 do: [ :index |
aBlock value: (table at: index) ]
1 to: size do: [ :index | aBlock value: (values at: index) ]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
private
findIndexFor: aKey
1 to: size * 2 - 1 by: 2 do: [ :index |
(table at: index) = aKey
1 to: size do: [ :index |
(keys at: index) = aKey
ifTrue: [ ^ index ] ].
^ 0
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
private
grow
| newTable |
"#replaceFrom:to:with:startingAt: would be better but not portable"
newTable := Array new: 4 * size.
1 to: size * 2 do: [ :index |
newTable at: index put: (table at: index) ].
table := newTable
| newKeys newValues |
newKeys := Array new: 2 * size.
newValues := Array new: 2 * size.
1 to: size do: [ :index |
newKeys at: index put: (keys at: index).
newValues at: index put: (values at: index) ].
keys := newKeys.
values := newValues
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ initialization
initialize: anInteger
self initialize.
size := 0.
table := Array new: anInteger * 2
keys := Array new: anInteger.
values := Array new: anInteger
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
enumerating
keys
| keys i |
size = 0 ifTrue: [ ^ #() ].
i := 1.
keys := Array new: size.
1 to: size * 2 - 1 by: 2 do: [ :index |
keys at: i put: (table at: index).
i := i + 1 ].
^ keys
^ keys copyFrom: 1 to: size
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
enumerating
keysAndValuesDo: aBlock
1 to: size * 2 - 1 by: 2 do: [ :index |
aBlock
value: (table at: index)
value: (table at: index + 1) ]
1 to: size do: [ :index | aBlock value: (keys at: index) value: (values at: index) ]
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
enumerating
keysDo: aBlock
1 to: size * 2 - 1 by: 2 do: [ :index |
aBlock value: (table at: index) ]
1 to: size do: [ :each | aBlock value: (keys at: each) ]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
copying
postCopy
super postCopy.
table := table copy
keys := keys copy.
values := values copy
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
private
privateAt: aKey put: aValue
size * 2 = table size ifTrue: [ self grow ].
table at: (size * 2 + 1) put: aKey.
table at: (size * 2 + 2) put: aValue.
size := size + 1.
^ aValue
size = keys size ifTrue: [ self grow ].
keys at: (size := size + 1) put: aKey.
^ values at: size put: aValue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
private
removeIndex: index
| value |
value := table at: index * 2.
index to: size * 2 - 2 do: [ :i |
table at: i put: (table at: i + 2) ].
table at: size * 2 - 1 put: nil.
table at: size * 2 put: nil.
value := values at: index.
index to: size - 1 do:
[ :i |
keys at: i put: (keys at: i + 1).
values at: i put: (values at: i + 1) ].
keys at: size put: nil.
values at: size put: nil.
size := size - 1.
^ value
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
removing
accessing
removeKey: aKey
"Remove aKey from the receiver, raise an exception if the element is missing."

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
removing
accessing
removeKey: aKey ifAbsent: aBlock
"Remove aKey from the receiver, evaluate aBlock if the element is missing."

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
enumerating
values
| values i |
size = 0 ifTrue: [ ^ #() ].
i := 1.
values := Array new: size.
2 to: size * 2 by: 2 do: [ :index |
values at: i put: (table at: index).
i := i + 1 ].
^ values
^ values copyFrom: 1 to: size
Loading
X Tutup