1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- Smalltalk createPackage: 'Kernel-Dag'!
- Object subclass: #DagNode
- instanceVariableNames: ''
- package: 'Kernel-Dag'!
- !DagNode commentStamp!
- I am the abstract root class of any directed acyclic graph.
- Concrete classes should implement `dagChildren` and `dagChildren:`
- to get / set direct successor nodes (aka child nodes / subnodes).!
- !DagNode methodsFor: 'accessing'!
- allDagChildren
- | allNodes |
-
- allNodes := self dagChildren asSet.
- self dagChildren do: [ :each |
- allNodes addAll: each allDagChildren ].
-
- ^ allNodes
- !
- dagChildren
- self subclassResponsibility
- !
- dagChildren: aCollection
- self subclassResponsibility
- ! !
- !DagNode methodsFor: 'testing'!
- isDagNode
- ^ true
- ! !
- DagNode subclass: #DagParentNode
- instanceVariableNames: 'nodes'
- package: 'Kernel-Dag'!
- !DagParentNode commentStamp!
- I am `DagNode` that stores a collection of its children,
- lazy initialized to empty array.
- I can `addDagChild:` to add a child.!
- !DagParentNode methodsFor: 'accessing'!
- addDagChild: aDagNode
- self dagChildren add: aDagNode
- !
- dagChildren
- ^ nodes ifNil: [ nodes := Array new ]
- !
- dagChildren: aCollection
- nodes := aCollection
- ! !
- DagNode subclass: #DagSink
- instanceVariableNames: 'nodes'
- package: 'Kernel-Dag'!
- !DagSink commentStamp!
- I am `DagNode` with no direct successors.
- Sending `dagChildren:` with empty collection is legal.!
- !DagSink methodsFor: 'accessing'!
- dagChildren
- ^ #()
- !
- dagChildren: aCollection
- aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]
- ! !
- !Object methodsFor: '*Kernel-Dag'!
- isDagNode
- ^ false
- ! !
|