-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDAGFrontier.class.st
More file actions
58 lines (49 loc) · 1.73 KB
/
Copy pathDAGFrontier.class.st
File metadata and controls
58 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"
A DAGFrontier is used to iterate a directed acyclic graph (DAG) respecting the dependencies between nodes. A client does not create it directly, but sends the message ""frontier"" to the DAG in question.
At any moment it holds a ""frontier"" of nodes that can be accessed. When any node in the frontier has been processed, it can be removed from the frontier, and the frontier will be updated if necessary (in situ).
Instance variables:
frontier <Set> of nodes on the frontier, empty if the whole DAG has been enumerated.
bag <Bag> of nodes, used to calculate updates to the frontier.
Clients of this class must *not* modify the frontier set, only access it.
"
Class {
#name : #DAGFrontier,
#superclass : #Object,
#instVars : [
'frontier',
'bag'
],
#category : #'Mathematics-Graphs-Algorithms'
}
{ #category : #'instance creation' }
DAGFrontier class >> on: rootedGraph [
"Create a frontier object to enumerate the graph."
| remaining frontier |
"Build a Bag of non-root nodes, each node once in the Bag for every predecessor."
frontier := rootedGraph rootNodes asOrderedCollection.
remaining := Bag new.
rootedGraph nodesDo: [:node| node neighborsDo: [:n| remaining add: n]].
^ self new frontier: frontier bag: remaining
]
{ #category : #accessing }
DAGFrontier >> frontier [
^frontier
]
{ #category : #initialization }
DAGFrontier >> frontier: f bag: remaining [
frontier := f.
bag := remaining
]
{ #category : #advancing }
DAGFrontier >> remove: frontierObject [
frontier remove: frontierObject.
frontierObject neighborsDo:
[ :neighbor |
(bag remove: neighbor) = 0
ifTrue: [frontier add: neighbor]].
^frontierObject
]
{ #category : #advancing }
DAGFrontier >> removeAll: collection [
collection do: [ :n | self remove: n]
]