-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
319 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
Class { | ||
#name : #DCLeftOverLeafMatcher, | ||
#superclass : #Object, | ||
#instVars : [ | ||
'rootSrc', | ||
'rootDest' | ||
], | ||
#category : #'DomainCode-Diff' | ||
} | ||
|
||
{ #category : #'as yet unclassified' } | ||
DCLeftOverLeafMatcher >> handleAmbiguousMappings: aCollection for: aMapping [ | ||
|
||
| comparator | | ||
comparator := DCMappingComparator new | ||
rootSrc: rootSrc rootDest: rootDest; | ||
mappingStore: aMapping. | ||
|
||
aCollection sort: [:m1 :m2 | | s1 s2 | | ||
s1 := m1 first detectMax: [:t | t recursiveSubmorphCount]. | ||
s2 := m2 first detectMax: [:t | t recursiveSubmorphCount]. | ||
s1 recursiveSubmorphCount < s2 recursiveSubmorphCount]. | ||
|
||
aCollection do: [:entry | | candidates | | ||
candidates := Array streamContents: [:s | entry first do: [:src | entry second do: [:dest | s nextPut: {src. dest}]]]. | ||
|
||
(candidates sort: [:m1 :m2 | (comparator compare: m1 with: m2) <= 0]) do: [:mapping | (aMapping areBothUnmappedSrc: mapping first dest: mapping second) ifTrue: [aMapping addRecursiveMappingFrom: mapping first to: mapping second]]] | ||
] | ||
|
||
{ #category : #'as yet unclassified' } | ||
DCLeftOverLeafMatcher >> matchFrom: src to: dest in: aMapping [ | ||
|
||
| ambiguousMappings srcTrees destTrees | | ||
rootSrc := src. | ||
rootDest := dest. | ||
|
||
ambiguousMappings := OrderedCollection new. | ||
srcTrees := DCPriorityTreeQueue new | ||
minimumHeight: 0; | ||
addAll: (Array streamContents: [:s | src allMorphsDo: [:k | (aMapping isSrcMapped: k) ifFalse: [s nextPut: k]]]). | ||
destTrees := DCPriorityTreeQueue new | ||
minimumHeight: 0; | ||
addAll: (Array streamContents: [:s | dest allMorphsDo: [:k | (aMapping isDestMapped: k) ifFalse: [s nextPut: k]]]). | ||
|
||
[ | ||
self synchronizePriority: srcTrees with: destTrees. | ||
srcTrees notEmpty and: [destTrees notEmpty]] whileTrue: [ | mapper | | ||
mapper := DCHashBasedMapper new. | ||
srcTrees removeHighest do: [:t | mapper addSrc: t]. | ||
destTrees removeHighest do: [:t | mapper addDest: t]. | ||
mapper uniqueEntries do: [:entry | aMapping addRecursiveMappingFrom: entry first anyOne to: entry second anyOne]. | ||
ambiguousMappings addAll: mapper ambiguousEntries. | ||
mapper unmappedEntries do: [:entry | | ||
entry first do: [:t | srcTrees addTree: t]. | ||
entry second do: [:t | destTrees addTree: t]]]. | ||
|
||
self handleAmbiguousMappings: ambiguousMappings for: aMapping | ||
] | ||
|
||
{ #category : #'as yet unclassified' } | ||
DCLeftOverLeafMatcher >> synchronizePriority: aQueue with: anotherQueue [ | ||
|
||
[(aQueue notEmpty and: [anotherQueue notEmpty]) and: [aQueue first treeHeight ~= anotherQueue first treeHeight]] whileTrue: [ | ||
aQueue first treeHeight > anotherQueue first treeHeight | ||
ifTrue: [aQueue removeHighestAndOpen] | ||
ifFalse: [anotherQueue removeHighestAndOpen]]. | ||
|
||
(aQueue isEmpty or: [anotherQueue isEmpty]) ifTrue: [ | ||
aQueue removeAll. | ||
anotherQueue removeAll. | ||
^ false]. | ||
^ true | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.