eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'PluggableSet':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: PluggableSet


Inheritance:

   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

Description:


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).

copyright

COPYRIGHT (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.

Class protocol:

instance creation
o  hashWith: hashFunctionArg compareWith: compareFunctionArg
return a set which hashes using the given hash function
and compare function (both are one-arg blocks)


Instance protocol:

accessing
o  hashWith: hashFunctionArg compareWith: compareFunctionArg
specify how to hash and how to compare elements
(see example on the class side)

copying
o  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
o  collisionsFor: key
Return the number of searches - 1 required for key

o  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

o  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

o  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

o  hashFor: aKey
return an initial index given a key.


Examples:


|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'.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 17:15:20 GMT