⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collections-graphs.st

📁 編譯器的語法產生器
💻 ST
字号:
OrderedCollection variableSubclass: #Graph
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Collections-Graphs'!
Graph comment:
'=================================================
    Copyright (c) 1992 by Justin O. Graver.
    All rights reserved (with exceptions).
    For complete information evaluate "Object tgenCopyright."
=================================================

I am an abstract class of graphs.'!

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

Graph class
	instanceVariableNames: ''!


!Graph class methodsFor: 'instance creation'!

preferredNodeClass

	^self subclassResponsibility!

withNodesLabeled: aCollection 

	| newGraph |
	aCollection size ~= aCollection asSet size ifTrue: [self notify: 'warning:  duplicate node names specifed for graph'].
	newGraph := self new: aCollection size.
	aCollection do: [:nodeName | newGraph add: (self preferredNodeClass label: nodeName)].
	^newGraph! !

Graph variableSubclass: #DirectedGraph
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Collections-Graphs'!
DirectedGraph comment:
'=================================================
    Copyright (c) 1992 by Justin O. Graver.
    All rights reserved (with exceptions).
    For complete information evaluate "Object tgenCopyright."
=================================================

This class represents a directed graph.'!


!DirectedGraph methodsFor: 'enumerating'!

nodesDo: aBlock 

	self do: aBlock! !

!DirectedGraph methodsFor: 'modifying'!

addEdgeFrom: node1 to: node2 

	node2 addPredecessor: node1! !

DirectedGraph variableSubclass: #LabeledDigraph
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Collections-Graphs'!
LabeledDigraph comment:
'=================================================
    Copyright (c) 1992 by Justin O. Graver.
    All rights reserved (with exceptions).
    For complete information evaluate "Object tgenCopyright."
=================================================

This class represents a directed graph whose edges are labeled.'!


!LabeledDigraph methodsFor: 'modifying'!

addEdgeFromNodeLabeled: label1 toNodeLabeled: label2 

	| node1 node2 |
	label1 ~= label2
		ifTrue: 
			["self edges are implicit and not represented"
			node1 := self detect: [:node | node label = label1].
			node2 := self detect: [:node | node label = label2].
			self addEdgeFrom: node1 to: node2]! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

LabeledDigraph class
	instanceVariableNames: ''!


!LabeledDigraph class methodsFor: 'instance creation'!

preferredNodeClass

	^NodeLabeledDigraphNode! !

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -