Advertisement
Guest User

Untitled

a guest
Jun 19th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. initialize: size
  2.     "metoda instancji"
  3.     next := Array new: size.
  4.     previous := Array new: size.
  5.     value := nil
  6.  
  7. new: aSize
  8.     "metoda klasy"
  9.     ^super new initialize: aSize
  10.  
  11. shape: intCollection
  12.     | nodes intArray mySize iterator iteratorIdx iteratorUpdater  nodesCount node a b c change multipleBy|
  13.    
  14.     intArray := intCollection asArray.
  15.     mySize := intArray size.
  16.    
  17.     iterator := Array new: mySize.
  18.     nodesCount := 1.
  19.     1 to: mySize do: [:idx|
  20.         iterator at: idx put: 1.
  21.         nodesCount := nodesCount * (intArray  at: idx)
  22.     ].
  23.    
  24.     nodes := Array new: nodesCount.
  25.     1 to: nodesCount do: [:idx |
  26.         nodes at: idx put: (Torus new: mySize ).
  27.     ].
  28.    
  29.    
  30.    
  31.     1 to: nodesCount do: [:idx |
  32.         node := (nodes at: idx).
  33.        
  34.         multipleBy := 1.
  35.         1 to: mySize do: [:i |
  36.             "next"
  37.             a := iterator at: i.
  38.             b := a + 1.
  39.             (b < (intArray at: i)) ifTrue: [
  40.                 change := multipleBy.
  41.                 c := idx + change.
  42.             ] ifFalse: [
  43.                 change := ((iterator at: i) - 1) * multipleBy .
  44.                 c := idx - change.
  45.             ].
  46.             (node next) at: i put: (nodes at: c).
  47.            
  48.             "previous"
  49.             b := a - 1.
  50.             (b > 0) ifTrue: [
  51.                 change := multipleBy.
  52.                 c := idx - change.
  53.             ] ifFalse: [
  54.                 change := ((intArray at: i) - 1) * multipleBy .
  55.                 c := idx + change.
  56.             ].
  57.             (node previous) at: i put: (nodes at: c).
  58.         ].
  59.        
  60.         (idx < nodesCount) ifTrue: [
  61.             iteratorIdx := 1.
  62.             iteratorUpdater := (iterator at: iteratorIdx) + 1.
  63.             [iteratorUpdater > (intArray at: iteratorIdx )] whileTrue: [
  64.                 iterator at: iteratorIdx put: 1.
  65.                 iteratorIdx := iteratorIdx + 1.
  66.                 iteratorUpdater := (iterator at: iteratorIdx) + 1.
  67.             ].
  68.             iterator at: iteratorIdx put: iteratorUpdater.
  69.         ].
  70.        
  71.     ].
  72.     ^(nodes at: 1).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement