|
Class: PluggableSet
Object
|
+--Collection
|
+--Set
|
+--PluggableSet
- Package:
- stx:libbasic2
- Category:
- Collections-Unordered
- Version:
- rev:
1.9
date: 2023/05/12 09:03:48
- user: cg
- file: PluggableSet.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
a set where the hash- and compare functions can be provided externally.
Useful if '=' and 'hash' cannot be used for comparing, and you have to
provide your own compare+hash functions (as blocks).
copyrightCOPYRIGHT (c) 2014 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
hashWith: hashFunctionArg compareWith: compareFunctionArg
-
return a set which hashes using the given hash function
and compare function (both are one-arg blocks)
accessing
-
hashWith: hashFunctionArg compareWith: compareFunctionArg
-
specify how to hash and how to compare elements
(see example on the class side)
copying
-
copyWithout: anElement
-
return a new collection consisting of a copy of the receiver, with
ALL elements equal to elementToSkip are left out.
No error is reported, if elementToSkip is not in the collection.
Usage example(s):
#(1 2 3 4 5 6 7) asSet copyWithout:5
|
private
-
collisionsFor: key
-
Return the number of searches - 1 required for key
-
find: key ifAbsent: aBlock
-
Look for the key in the receiver. If it is found, return
the index of the slot containing the key, otherwise
return the value of evaluating aBlock.
Redefined to compare for identity instead of equality
-
findKeyOrNil: key
-
Look for the key in the receiver.
If it is found, return return the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present
-
findKeyOrNilOrDeletedEntry: key
-
Look for the key in the receiver.
If it is found, return return the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present
-
hashFor: aKey
-
return an initial index given a key.
|s|
s := PluggableSet
hashWith:[:k | k size]
compareWith:[:a :b | a notNil and:[b notNil and:[a asLowercase = b asLowercase]]].
s add:'hello'.
s add:'world'.
s add:'abc'.
s add:'Hello'.
s add:'heLLo'.
s add:'ABC'.
s add:'WORLD'.
s size.
s includes:'heLlo'.
s includes:'wOrLd'.
s includes:'wOrLds'.
|