-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssert-YamlNodeKeyUnique.ps1
More file actions
61 lines (53 loc) · 2.11 KB
/
Copy pathAssert-YamlNodeKeyUnique.ps1
File metadata and controls
61 lines (53 loc) · 2.11 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
59
60
61
function Assert-YamlNodeKeyUnique {
<#
.SYNOPSIS
Indexes one representation key and confirms equality for fingerprint candidates.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[pscustomobject] $Node,
[Parameter(Mandatory)]
[AllowEmptyCollection()]
[System.Collections.Generic.Dictionary[string, object]] $Buckets,
[Parameter(Mandatory)]
[AllowEmptyCollection()]
[System.Collections.Generic.Dictionary[int, string]] $FingerprintCache,
[Parameter(Mandatory)]
[System.Security.Cryptography.HashAlgorithm] $FingerprintHasher,
[Parameter(Mandatory)]
[string] $DuplicateMessage,
[Parameter()]
[AllowNull()]
[pscustomobject] $RemovalWorkState,
[Parameter()]
[AllowNull()]
[pscustomobject] $EqualityState,
[Parameter()]
[AllowNull()]
[System.Collections.Generic.Dictionary[int, string]] $EqualityFingerprintCache
)
$fingerprint = Get-YamlNodeFingerprint -Node $Node `
-Active ([System.Collections.Generic.HashSet[int]]::new()) `
-Cache $FingerprintCache -Hasher $FingerprintHasher `
-RemovalWorkState $RemovalWorkState
$bucket = $null
if (-not $Buckets.TryGetValue($fingerprint, [ref] $bucket)) {
$bucket = [System.Collections.Generic.List[object]]::new()
$Buckets[$fingerprint] = $bucket
} elseif ($null -eq $EqualityState) {
throw (New-YamlException -Start $Node.Start -End $Node.End `
-ErrorId 'YamlDuplicateKey' -Message $DuplicateMessage)
} else {
foreach ($candidate in $bucket) {
if (Test-YamlMergeNodeEqual -Node $candidate -OtherNode $Node `
-State $EqualityState `
-LeftFingerprintCache $EqualityFingerprintCache `
-RightFingerprintCache $EqualityFingerprintCache) {
throw (New-YamlException -Start $Node.Start -End $Node.End `
-ErrorId 'YamlDuplicateKey' -Message $DuplicateMessage)
}
}
}
$bucket.Add($Node)
}