Skip to content

Commit

Permalink
Ignore un-nested permutations which are not possible
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Jan 4, 2024
1 parent 6b308d7 commit 392c609
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
12 changes: 12 additions & 0 deletions packages/Sandblocks-Core/SBBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,18 @@ SBBlock >> parentHasDynamicNumberOfChildren [
^ self parentSandblock fixedNumberOfChildren not
]

{ #category : #accessing }
SBBlock >> parentVariant [

^ self parentSandblock
ifNil: [nil]
ifNotNil: [:theParent |
theParent isVariant
ifTrue: [theParent]
ifFalse: [theParent parentVariant]]

]

{ #category : #actions }
SBBlock >> pasteAfter [
<action>
Expand Down
23 changes: 23 additions & 0 deletions packages/Sandblocks-Smalltalk/SBVariant.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,29 @@ SBVariant >> alternativesEqual: otherAlternatives [
areSame]
]

{ #category : #converting }
SBVariant >> asNestedPaths [

| allPaths |
allPaths := OrderedCollection new.
self asNestedPaths: allPaths currentPath: (SBPermutation new referencedVariants: OrderedCollection new).
^ allPaths
]

{ #category : #converting }
SBVariant >> asNestedPaths: allPaths currentPath: aPermutation [

"Private helper function"
self namedBlocks withIndexCollect: [:aNamedBlock :i | | nestedVariants currentPath |
nestedVariants := aNamedBlock block childSandblocks select: #isVariant.
currentPath := aPermutation copyWith: (self id -> i).
currentPath referencedVariants: (aPermutation referencedVariants copyWith: self).
nestedVariants
ifEmpty: [allPaths add: currentPath]
ifNotEmpty: [:children | children do: [:child |
child asNestedPaths: allPaths currentPath: currentPath]]]
]

{ #category : #converting }
SBVariant >> asProxy [

Expand Down
31 changes: 20 additions & 11 deletions packages/Sandblocks-Utils/SBPermutation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,32 @@ Class {
{ #category : #utils }
SBPermutation class >> allPermutationsOf: aCollectionOfVariants [

| permutations |
| permutations topLevelVariants nestedPermutations |
aCollectionOfVariants ifEmpty:[^{SBNilPermutation new referencedVariants: {}}].
permutations := (1 to: aCollectionOfVariants first alternativesCount) collect: #asArray.
topLevelVariants := aCollectionOfVariants select: [:aVariant | aVariant parentVariant isNil].
nestedPermutations := topLevelVariants collect: #asNestedPaths.
permutations := nestedPermutations first.

(2 to: aCollectionOfVariants size) do: [:i | | alternatives |
alternatives := (aCollectionOfVariants at: i) alternativesCount.
permutations := permutations gather: [:aCollectionOfIndexes |
(1 to: alternatives) collect: [:aTabIndex |
{aCollectionOfIndexes. aTabIndex} flatten]]].
(2 to: topLevelVariants size) do: [:i | | nestedPermutation |
nestedPermutation := (nestedPermutations at: i).
permutations := permutations gather: [:aPermutation |
nestedPermutation collect: [:aNestedPermutation | self newCombinedOf: aPermutation and: aNestedPermutation]]].

^ permutations collect: [:aCollectionOfIndexes |
(self withAll: (aCollectionOfIndexes withIndexCollect: [:anAlternativeIndex :aVariantIndex |
(aCollectionOfVariants at: aVariantIndex) id -> anAlternativeIndex]))
referencedVariants: aCollectionOfVariants]
^ permutations

]

{ #category : #utils }
SBPermutation class >> newCombinedOf: onePermutation and: anotherPermutation [

| result |
result := self new referencedVariants: (onePermutation referencedVariants, anotherPermutation referencedVariants).
result addAll: onePermutation.
result addAll: anotherPermutation.
^ result

]

{ #category : #actions }
SBPermutation >> apply [

Expand Down

0 comments on commit 392c609

Please sign in to comment.