SkipListNode.st
changeset 4398 e87e78eb5234
equal deleted inserted replaced
4397:dd62ed6075b2 4398:e87e78eb5234
       
     1 "{ Package: 'stx:libbasic2' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 Object subclass:#SkipListNode
       
     6 	instanceVariableNames:'pointers object'
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'Collections-Ordered-Trees-Private'
       
    10 !
       
    11 
       
    12 
       
    13 !SkipListNode class methodsFor:'instance creation'!
       
    14 
       
    15 new: maxLevel
       
    16 	^ super new initialize: maxLevel
       
    17 !
       
    18 
       
    19 on: element level: maxLevel 
       
    20         ^ (self new: maxLevel) object: element
       
    21 
       
    22     "Modified (format): / 18-06-2017 / 17:47:43 / cg"
       
    23 !
       
    24 
       
    25 tailOfLevel: n
       
    26 	^ self on: nil level: n
       
    27 ! !
       
    28 
       
    29 !SkipListNode methodsFor:'accessing'!
       
    30 
       
    31 atForward: i put: node
       
    32 	^ pointers at: i put: node
       
    33 !
       
    34 
       
    35 forward: i 
       
    36 	^ pointers at: i
       
    37 !
       
    38 
       
    39 level
       
    40 	^ pointers size
       
    41 !
       
    42 
       
    43 next
       
    44 	^ pointers first
       
    45 !
       
    46 
       
    47 object
       
    48 	^ object
       
    49 ! !
       
    50 
       
    51 !SkipListNode methodsFor:'initialization'!
       
    52 
       
    53 initialize: maxLevel
       
    54         pointers := Array new: maxLevel
       
    55 
       
    56     "Modified (format): / 18-06-2017 / 17:47:07 / cg"
       
    57 ! !
       
    58 
       
    59 !SkipListNode methodsFor:'printing'!
       
    60 
       
    61 printOn: aStream
       
    62         | first |
       
    63         aStream
       
    64                 nextPut: $[;
       
    65                 nextPutAll: object printString;
       
    66                 nextPutAll: ']-->('.
       
    67         first := true.
       
    68         pointers do: [:node |
       
    69                 first ifTrue: [first := false] ifFalse: [aStream space].
       
    70                 aStream nextPutAll: (node isNil ifTrue: ['*'] ifFalse: [node object printString])].
       
    71         aStream nextPut: $)
       
    72 
       
    73     "Modified: / 18-06-2017 / 17:47:35 / cg"
       
    74 ! !
       
    75 
       
    76 !SkipListNode methodsFor:'private'!
       
    77 
       
    78 object: anObject
       
    79         object := anObject
       
    80 
       
    81     "Modified (format): / 18-06-2017 / 17:47:13 / cg"
       
    82 ! !
       
    83 
       
    84 !SkipListNode class methodsFor:'documentation'!
       
    85 
       
    86 version
       
    87     ^ '$Header$'
       
    88 !
       
    89 
       
    90 version_CVS
       
    91     ^ '$Header$'
       
    92 ! !
       
    93