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
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
language: smalltalk
sudo: false
smalltalk:
- Pharo-6.0
- Pharo-5.0
- Pharo-4.0
- Pharo-3.0
- Squeak-4.5
- Squeak-5.1
- Squeak-5.0
- Squeak-4.6
- Squeak-4.5
- GemStone-3.1.0.6
- GemStone-3.2.12
- GemStone-3.3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
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
@@ -1,6 +1,3 @@
accessing
allAt: aKey
^ Array streamContents: [ :stream |
1 to: size do: [ :index |
(keys at: index) = aKey
ifTrue: [ stream nextPut: (values at: index) ] ] ]
^ self privateAllAt: aKey startingAt: 1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
adding
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
@@ -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
@@ -1,10 +1,10 @@
accessing
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 streamContents: [ :stream |
removed := Array new: 2 streamContents: [ :stream |
| index |
[ (index := self findIndexFor: aKey) = 0 ] whileFalse: [
stream nextPut: (self removeIndex: index) ] ].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
},
"instance" : {
"add:" : "lr 7/25/2011 19:52",
"allAt:" : "jf 2/15/2010 15:39",
"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",
"removeKey:ifAbsent:" : "jf 2/15/2010 14:43" } }
"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
Expand Up @@ -13,4 +13,8 @@ resolveWith: aDictionary
aDictionary at: (each copyReplaceAll: '-Pharo-' with: '-Pharo40-') ifAbsent: [
"try -Pharo50-"
aDictionary at: (each copyReplaceAll: '-Pharo-' with: '-Pharo50-') ifAbsent: [
self error: self name printString , ' depends on unknown package ' , each printString ] ] ] ] ] ] ]
"try -Squeak-"
aDictionary at: (each copyReplaceAll: '-Pharo-' with: '-Squeak-') ifAbsent: [
"try -Squeak5-"
aDictionary at: (each copyReplaceAll: '-Pharo-' with: '-Squeak5-') ifAbsent: [
self error: self name printString , ' depends on unknown package ' , each printString ] ] ] ] ] ] ] ] ]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"name" : "lr 2/17/2010 15:18",
"name:" : "lr 10/25/2009 11:26",
"printOn:" : "merged 10/20/2008 09:24",
"resolveWith:" : "JohanBrichau 3/26/2016 15:54",
"resolveWith:" : "TravisCI 8/23/2016 10:48",
"seasideAddonsUrl" : "pmm 9/12/2013 15:59",
"seasideLGPLUrl" : "pmm 9/12/2013 15:59",
"seasideUrl" : "pmm 9/12/2013 15:58",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ version info
version
"Answer the Grease version"

^ (GRVersion major: 1 minor: 1 revision: 10)
^ (GRVersion major: 1 minor: 2 revision: 8)
yourself
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"semaphoreClass" : "jf 1/22/2009 02:10",
"stackDepth" : "jf 1/22/2009 02:11",
"terminateProcess:" : "jf 2/6/2009 16:00",
"version" : "JohanBrichau 7/20/2014 17:51",
"version" : "JohanBrichau 5/5/2016 12:55",
"versionString" : "jf 2/9/2010 00:57",
"weakDictionaryOfSize:" : "jf 1/22/2009 02:11",
"write:toFile:inFolder:" : "pmm 8/19/2014 10:11",
Expand Down
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.
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.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
adding
add: anAssociation
self at: anAssociation key put: anAssociation value.
^ anAssociation
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
adding
addAll: aDictionary
aDictionary keysAndValuesDo: [ :key :value | self add: key -> value ].
aDictionary keysAndValuesDo: [ :key :value | self at: key put: value ].
^ aDictionary
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: [ values at: index ]
ifFalse: [ table at: index + 1 ]
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: [ values at: index ]
ifFalse: [ table at: index + 1 ]
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: (values at: index) ]
^ index = 0 ifFalse: [ aBlock value: (table at: index + 1) ]
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: [ values at: index put: aValue ]
ifFalse: [ table at: index + 1 put: aValue ]
ifTrue: [ self privateAt: aKey put: aValue ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
enumerating
do: aBlock
1 to: size do: [ :index | aBlock value: (values at: index) ]
2 to: size * 2 by: 2 do: [ :index |
aBlock value: (table at: index) ]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
private
findIndexFor: aKey
1 to: size do: [ :index |
(keys at: index) = aKey
1 to: size * 2 - 1 by: 2 do: [ :index |
(table at: index) = aKey
ifTrue: [ ^ index ] ].
^ 0
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
private
grow
| 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
| 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ initialization
initialize: anInteger
self initialize.
size := 0.
keys := Array new: anInteger.
values := Array new: anInteger
table := Array new: anInteger * 2
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
enumerating
keys
^ keys copyFrom: 1 to: size
| 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
enumerating
keysAndValuesDo: aBlock
1 to: size do: [ :index | aBlock value: (keys at: index) value: (values at: index) ]
1 to: size * 2 - 1 by: 2 do: [ :index |
aBlock
value: (table at: index)
value: (table at: index + 1) ]
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
enumerating
keysDo: aBlock
1 to: size do: [ :each | aBlock value: (keys at: each) ]
1 to: size * 2 - 1 by: 2 do: [ :index |
aBlock value: (table at: index) ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
copying
postCopy
super postCopy.
keys := keys copy.
values := values copy
table := table copy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
private
privateAt: aKey put: aValue
size = keys size ifTrue: [ self grow ].
keys at: (size := size + 1) put: aKey.
^ values at: size 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
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
private
removeIndex: index
| value |
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.
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.
size := size - 1.
^ value
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
removing
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 @@
accessing
removing
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,3 +1,10 @@
enumerating
values
^ values copyFrom: 1 to: size
| 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
"withAll:" : "jf 2/15/2010 22:50" },
"instance" : {
"add:" : "lr 7/25/2011 19:51",
"addAll:" : "jf 2/15/2010 22:56",
"addAll:" : "pmm 8/25/2016 12:31",
"associations" : "lr 10/28/2007 14:42",
"associationsDo:" : "lr 8/20/2007 13:45",
"at:" : "lr 10/28/2007 14:42",
"at:ifAbsent:" : "lr 10/28/2007 14:42",
"at:ifAbsentPut:" : "lr 10/28/2007 14:42",
"at:ifPresent:" : "lr 10/28/2007 14:42",
"at:put:" : "lr 10/28/2007 14:42",
"do:" : "jf 12/29/2009 20:38",
"at:ifAbsent:" : "pmm 8/22/2016 12:08",
"at:ifAbsentPut:" : "pmm 8/22/2016 12:09",
"at:ifPresent:" : "pmm 8/22/2016 12:09",
"at:put:" : "pmm 8/22/2016 12:09",
"do:" : "pmm 8/22/2016 12:02",
"errorKeyNotFound" : "lr 7/12/2007 13:18",
"findIndexFor:" : "lr 10/28/2007 14:42",
"grow" : "lr 6/6/2007 19:12",
"findIndexFor:" : "pmm 8/22/2016 12:17",
"grow" : "pmm 8/25/2016 11:00",
"includesKey:" : "lr 10/28/2007 14:42",
"initialize:" : "jf 3/13/2009 17:48",
"initialize:" : "pmm 8/22/2016 11:52",
"isCollection" : "jf 2/15/2010 15:47",
"isEmpty" : "lr 7/9/2007 08:13",
"keys" : "lr 7/9/2007 10:37",
"keysAndValuesDo:" : "lr 6/7/2007 08:04",
"keysDo:" : "lr 8/17/2007 11:52",
"postCopy" : "lr 7/9/2007 07:50",
"keys" : "pmm 8/22/2016 12:33",
"keysAndValuesDo:" : "pmm 8/25/2016 15:04",
"keysDo:" : "pmm 8/22/2016 12:18",
"postCopy" : "pmm 8/22/2016 11:56",
"printOn:" : "pmm 1/22/2012 16:32",
"privateAt:put:" : "lr 6/6/2007 19:28",
"removeIndex:" : "jf 2/15/2010 14:33",
"privateAt:put:" : "pmm 8/22/2016 12:15",
"removeIndex:" : "pmm 8/22/2016 12:29",
"removeKey:" : "lr 7/12/2007 13:18",
"removeKey:ifAbsent:" : "jf 2/15/2010 14:40",
"size" : "lr 7/9/2007 10:38",
"values" : "lr 7/9/2007 10:38" } }
"values" : "pmm 8/22/2016 12:34" } }
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
],
"classvars" : [
],
"commentStamp" : "jf 2/15/2010 15:51",
"commentStamp" : "pmm 8/22/2016 11:49",
"instvars" : [
"size",
"keys",
"values" ],
"table" ],
"name" : "GRSmallDictionary",
"pools" : [
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
instance creation
new: anInteger
^ self basicNew initialize: anInteger; yourself
Loading
X Tutup