From 4e801e4e2258f3639c5b59b825a7eeb0eb1b93dc Mon Sep 17 00:00:00 2001 From: Boris Shingarov Date: Wed, 6 Nov 2024 03:15:45 -0500 Subject: [PATCH] [PreSmalltalks] Remove IndexedSet As a data structure it is useful and attractive, but after the simplification of the Hotel it is not actually necessary, so why not score a few millivallouds. --- .../IndexedSetTest.class.st | 34 ------------- src/PreSmalltalks/IndexedSet.class.st | 49 ------------------- 2 files changed, 83 deletions(-) delete mode 100644 src/PreSmalltalks-Tests/IndexedSetTest.class.st delete mode 100644 src/PreSmalltalks/IndexedSet.class.st diff --git a/src/PreSmalltalks-Tests/IndexedSetTest.class.st b/src/PreSmalltalks-Tests/IndexedSetTest.class.st deleted file mode 100644 index e92bcd280..000000000 --- a/src/PreSmalltalks-Tests/IndexedSetTest.class.st +++ /dev/null @@ -1,34 +0,0 @@ -Class { - #name : #IndexedSetTest, - #superclass : #TestCase, - #instVars : [ - 'hotel' - ], - #category : #'PreSmalltalks-Tests' -} - -{ #category : #running } -IndexedSetTest >> setUp [ - hotel := IndexedSet new -] - -{ #category : #tests } -IndexedSetTest >> testAddGuest [ - self assert: hotel size equals: 0. - self assert: (hotel addElement: 'abc') equals: 1. - self assert: (hotel addElement: 'def') equals: 2. - self assert: (hotel addElement: 'abc') equals: 1. - -] - -{ #category : #tests } -IndexedSetTest >> testIndicesStay [ - self assert: hotel size equals: 0. - self assert: (hotel addElement: 'a') equals: 1. - self assert: (hotel addElement: 'b') equals: 2. - self assert: (hotel addElement: 'c') equals: 3. - self assert: (hotel addElement: 'a') equals: 1. - hotel remove: 'a'. - self assert: (hotel addElement: 'b') equals: 2. - self assert: (hotel addElement: 'c') equals: 3. -] diff --git a/src/PreSmalltalks/IndexedSet.class.st b/src/PreSmalltalks/IndexedSet.class.st deleted file mode 100644 index d4b2d7b9e..000000000 --- a/src/PreSmalltalks/IndexedSet.class.st +++ /dev/null @@ -1,49 +0,0 @@ -" -I am a set whose elements are numbered by integer indices. -No two elements have the same index. -When elements are added or removed, the other elements do not change their indices. - -An IndexedSet can be thought of as a hotel: -each guest is assigned a room, and no two guests simultaneously share the same room. -However, if a guest moves out, the room *may* be reused. -" -Class { - #name : #IndexedSet, - #superclass : #Dictionary, - #category : #PreSmalltalks -} - -{ #category : #API } -IndexedSet >> addElement: anObject [ - "Add anObject. Answer its newly-assigned index. - If anObject is already a member of the receiver, - don't add it but simply answer its index." - - ^self keyAtValue: anObject ifAbsent: [ - | j | - j := self availableRoom. - self at: j put: anObject. - ^j ] - - -] - -{ #category : #private } -IndexedSet >> availableRoom [ - "^Integer fresh" - "TOTALLY BOGUS!!!" - ^self lowestNumberedAavailableRoom -] - -{ #category : #private } -IndexedSet >> lowestNumberedAavailableRoom [ - self isEmpty ifTrue: [^1]. - ^self keys max + 1 -] - -{ #category : #API } -IndexedSet >> remove: anObject [ - | j | - j := self keyAtValue: anObject ifAbsent: [ self errorNotFound: anObject ]. - self removeKey: j -]