eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SortedSet':

Home

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

Class: SortedSet


Inheritance:

   Object
   |
   +--Collection
      |
      +--Set
         |
         +--OrderedSet
            |
            +--SortedSet

Package:
stx:libbasic2
Category:
Collections-Sequenceable
Version:
rev: 1.5 date: 2019/02/10 12:48:50
user: cg
file: SortedSet.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


I am a subclass of Set whose elements are ordered in a
similar fashion to SortedCollection.
That is, I have both Set behavior (only keeping a single instance of
an element) but I also remember the sort order.

I have one additional instance variable:

order <SortedCollection>        Sorted collection of values reflecting the order 
                                in the set. 

[caveat:]
    a tree may be a better choice, 
    as although the set shows O(1) behavior when adding,
    the sortedCollection does not (especially as inserting is expensive). 
    A balanced tree would show O(lg n) behavior.


Related information:

    OrderedCollection
    Dictionary
    OrderedDictionary
    Set
    Bag

Class protocol:

instance creation
o  sortBlock: aBlock
return a new sortedSet, whe the sort order is defined by aBlock.
This must be a two-argument block which returns true if its arg1 has to come before
its arg2 in the collection.


Instance protocol:

accessing
o  sortBlock

adding & removing
o  addFirst: anObject
blocked; only the sort order determines the order

o  addLast: anObject
blocked; only the sort order determines the order

enumerating
o  collect: aBlock
for each element in the receiver, evaluate the argument, aBlock
and return a new collection with the results

usage example(s):

     #(1 2 3 4) collect:[:e | e odd]   
     (1 to:10) collect:[:e | e even]     

o  select: aBlock
return a new collection with all elements from the receiver, for which
the argument aBlock evaluates to true.
See also: #removeAllFoundIn: and #removeAllSuchThat:

usage example(s):

     #(1 2 3 4) select:[:e | e odd]   
     (1 to:10) select:[:e | e even]     

initialization
o  initializeOrder: anInteger

o  setSortBlock: aBlock


Examples:


        |s|

        s := SortedSet new.
        s add:'one'.
        s add:'two'.
        s add:'one'.
        s add:'two'.
        s add:'four'.
        s add:'three'.
        s size.         
        s do:[:each | Transcript showCR:each].         
        |s|

        s := SortedSet new.
        s add:'one'.
        s add:'two'.
        s add:'one'.
        s add:'two'.
        s add:'three'.
        s remove:'one'.
        s size.         
        s do:[:each | Transcript showCR:each].         
        |s|

        s := SortedSet new.
        s add:'one'.
        s add:'two'.
        s add:'three'.
        s add:'one'.
        s add:'two'.
        s add:'three'.
        s size.         
        Transcript showCR:s.         
        s removeFirst.
        Transcript showCR:s.         
        s removeFirst.
        Transcript showCR:s.         
        s removeFirst.
        Transcript showCR:s.         


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sat, 20 Apr 2024 06:49:20 GMT