- live browsing of Self object memory -

lobby traitsabstractSetOrDictionary

CopyDowns: vector

CreatorPath: traits abstractSetOrDictionary

4 Modules

parent* = traits collection

accessing

at:IfAbsent: =
( 
    if: k
    IsPresentDo: [|:v| v]
    IfAbsentDo: [b value: k])
includesKey: = ( if: k IsPresentDo: true IfAbsentDo: false)
selectAtRandom: = ( selectAtRandom: howMany IfFail: [|:e| error: e])
selectAtRandom:IfFail: =
( | r. x |
    size < howMany ifTrue: [^ fb value: 'not enough elements'].
    x: copy.
    r: copyRemoveAll.
    howMany do: [|ks. i. k|
      ks: x keys asVector.
      i: random integer: ks size.
      k: keys at: i.
      r add: (x at: k) WithKey: k.
      x remove: k.
    ].
    r)

adding

at:Put: =
( 
    if: k IsPresentPut: [v] AndDo: [self]
          IfAbsentPut:  [v] AndDo: [self])

comparing

< = ( error: 'sets and dictionaries are unordered')

copying

copy = ( sync: [unsafe_copy])
copyContaining: =
( 
    "override to optimize"
    (copyRemoveAll desiredMinCapacity: c size) addAll: c)
copyRemoveAll = ( clone removeAll)
clone = ( resend.clone resetLock)

fast accessing and adding

at:IfAbsentPut: =
( 
             if: k
    IsPresentDo: [|:v| v]
    IfAbsentPut: blk
          AndDo: [|:v| v])
If the specified key is present, return the value associated with it. If it is absent, add the result of the specified block and return it. -- aaa, 2/18/04
if:IsPresentDo: = ( if: k IsPresentDo: blk IfAbsentDo: [])
if:IsPresentDo:IfAbsentDo: =
( 
              if: k
    IsPresentAnd: false
             Put: [error: 'should not be called']
           AndDo: presentActionBlock
     IfAbsentAnd: false
             Put: [error: 'should not be called']
           AndDo: absentActionBlock)
if:IsPresentDo:IfAbsentPut:AndDo: =
( 
              if: k
    IsPresentAnd: false
             Put: [error: 'should not be called']
           AndDo: presentActionBlock
     IfAbsentAnd: true
             Put: newValueBlock
           AndDo: absentActionBlock)
If collection contains k invoke presentActionBlock with value at k. If k is absent, add result of evaluating newValueBlock on k, at key k (for dicts) and invoke absentActionBlock with new value.
if:IsPresentPut:AndDo:IfAbsentDo: =
( 
              if: k
    IsPresentAnd: true
             Put: replacementValueBlock
           AndDo: presentActionBlock
     IfAbsentAnd: false
             Put: [error: 'should not be called']
           AndDo: absentActionBlock)
if collection contains k, invoke replacementValueBlock with arg old value and replace contents at k with result of replacementValueBlock. Then invoke presentActionBlock with arg new value. If k is absent, invoke absentActionBlock with k.
if:IsPresentPut:AndDo:IfAbsentPut:AndDo: =
( 
              if: k
    IsPresentAnd: true
             Put: replacementValueBlock
           AndDo: presentActionBlock
     IfAbsentAnd: true
             Put: newValueBlock
           AndDo: absentActionBlock)
if collection contains k, invoke replacementValueBlock with arg old value and replace contents at k with result of replacementValueBlock. Then invoke presentActionBlock with arg new value. If k is absent, add result of evaluating newValueBlock at key k (for dicts) and invoke absentActionBlock with new value.

iterating

do: = ( sync: [unsafe_do: b])
with:Do: = ( sync: [ unsafe_with: c Do: b ])

not sorting

copySortBy: = ( error: 'cannot sort, try asVector sortBy:')

objects that cannot be keys

invalidKeysDo: =
( 
    "Override in children (such as hash-table-based sets
     or dictionaries) that cannot hold particular objects
     (like the emptyMarker or removedMarker)."
    self)

removing

remove:IfAbsent: = ( sync: [ unsafe_remove: v IfAbsent: fb ])
removeAll = ( sync: [unsafe_removeAll])
removeFirst = ( removeFirstIfAbsent: raiseError)
removeKey: =
( 
     removeKey: k
    IfAbsent: [error: k printString, ' is absent'])

sizing

desiredMinCapacity: = ( sync: [unsafe_desiredMinCapacity: s])
checkHash =
( 
    " check hashes; crude approximation"
    do: [| :v. :k. |
        (
          if: k
          IsPresentDo: [|:vv | v == vv]
          IfAbsentDo: false
        ) ifFalse: [error: 'hash changed'].
    ].
    self)

testing

isOrdered = false

transforming

universalSetAndDictionary

asUniversal =
( | c |
    c: self.
    invalidKeysDo: [|:k| c: c interposeHolderFor: k].
    c)
interposeHolderFor: = ( prototypeForUniversalSetOrDictionary copyFor: self Marker: marker)