Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3951 from joostjager/exclusive-group-sweeper
sweep: add exclusive groups
- Loading branch information
Showing
3 changed files
with
173 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package sweep | ||
|
||
// bucket contains a set of inputs that are not mutually exclusive. | ||
type bucket pendingInputs | ||
|
||
// tryAdd tries to add a new input to this bucket. | ||
func (b bucket) tryAdd(input *pendingInput) bool { | ||
exclusiveGroup := input.params.ExclusiveGroup | ||
if exclusiveGroup != nil { | ||
for _, input := range b { | ||
existingGroup := input.params.ExclusiveGroup | ||
if existingGroup != nil && | ||
*existingGroup == *exclusiveGroup { | ||
|
||
return false | ||
} | ||
} | ||
} | ||
|
||
b[*input.OutPoint()] = input | ||
|
||
return true | ||
} | ||
|
||
// bucketList is a list of buckets that contain non-mutually exclusive inputs. | ||
type bucketList struct { | ||
buckets []bucket | ||
} | ||
|
||
// add adds a new input. If the input is not accepted by any of the existing | ||
// buckets, a new bucket will be created. | ||
func (b *bucketList) add(input *pendingInput) { | ||
for _, existingBucket := range b.buckets { | ||
if existingBucket.tryAdd(input) { | ||
return | ||
} | ||
} | ||
|
||
// Create a new bucket and add the input. It is not necessary to check | ||
// the return value of tryAdd because it will always succeed on an empty | ||
// bucket. | ||
newBucket := make(bucket) | ||
newBucket.tryAdd(input) | ||
b.buckets = append(b.buckets, newBucket) | ||
} |
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