- live browsing of Self object memory -

lobby traitsorderedSet

CopyDowns: vector

CreatorPath: traits orderedSet

Module: orderedSet

adding

addFirst: =
( 
    unorderedElements
                   if: elem
          IsPresentDo: [^ self]
          IfAbsentPut: [elem]
                AndDo: [resend.addFirst: elem].
    self)
addLast: =
( 
    unorderedElements
                   if: elem
          IsPresentDo: [^ self]
          IfAbsentPut: [elem]
                AndDo: [resend.addLast: elem].
    self)

coercing

asList = ( list copyContaining: self)
asOrderedSet = ( self)

copying

copyRemoveAll = ( ((clone rep: rep copy) unorderedElements: unorderedElements copyRemoveAll) removeAll)

fast accessing

if:IsPresentDo:IfAbsentDo: =
( 
    unorderedElements if: k
             IsPresentDo: presentActionBlock
              IfAbsentDo: absentActionBlock)
if:IsPresentDo:IfAbsentPut:AndDo: =
( 
    unorderedElements if: k
             IsPresentDo: presentActionBlock
             IfAbsentPut: newValueBlock
                   AndDo: [|:newV. :oldK| resend.addLast: newV.
                                   absentActionBlock value: newV With: oldK ])
If collection contains k invoke presentActionBlock with value at k. If k is absent, add result of evaluating newValueBlock on k, and invoke absentActionBlock with new value.
if:IsPresentPut:AndDo:IfAbsentDo: =
( 
    unorderedElements if: k
            IsPresentPut: replacementValueBlock
                   AndDo: [|:newV. :oldK| firstLinkFor: k
                                      IfPresent: [|:lnk| lnk value: newV. ^ presentActionBlock value: newV With: oldK]
                                       IfAbsent: raiseError]
              IfAbsentDo: 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: =
( 
    unorderedElements if: k
            IsPresentPut: replacementValueBlock
                   AndDo: [|:newV. :oldK| firstLinkFor: k
                                      IfPresent: [|:lnk| lnk value: newV. ^ presentActionBlock value: newV With: oldK]
                                       IfAbsent: raiseError]
             IfAbsentPut: newValueBlock
                   AndDo: [|:newV. :oldK| resend.addLast: newV.
                                   absentActionBlock value: newV With: oldK])
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 and invoke absentActionBlock with new value.

printing

collectionName = 'orderedSet'

removing

remove:IfAbsent: =
( 
    unorderedElements remove: elem IfAbsent: [^ block value].
    resend.remove: elem IfAbsent: [error: 'should never get here'])
removeAll =
( 
    unorderedElements removeAll.
    resend.removeAll)
removeFirst =
( | v |
    v: resend.removeFirst.
    unorderedElements remove: v.
    v)
removeLast =
( | v |
    v: resend.removeLast.
    unorderedElements remove: v.
    v)

searching

includes: = ( unorderedElements includes: v)