Private/Baseline/New-BaselineIndex.ps1

function New-BaselineIndex {
    <#
    .SYNOPSIS
        Create indexed lookups for baseline policies.
     
    .DESCRIPTION
        Builds hashtables for fast policy lookup by ID, DisplayName, and normalized name.
        Enables O(1) lookups during comparison operations.
     
    .PARAMETER Baseline
        Array of baseline policy objects.
     
    .EXAMPLE
        $index = New-BaselineIndex -Baseline $baseline
        $policy = $index.ById["/providers/Microsoft.Authorization/policyDefinitions/123"]
     
    .OUTPUTS
        PSCustomObject with .ById, .ByName, and .ByNormName hashtables
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [object[]]$Baseline
    )
    
    $indexById = $Baseline | Group-Object -Property PolicyDefinitionId -AsHashTable -AsString
    $indexByName = $Baseline | Group-Object -Property PolicyDisplayName -AsHashTable -AsString
    $indexByNormName = New-PolicyIndex -Items $Baseline -NameProperty 'PolicyDisplayName'
    
    return [pscustomobject]@{
        ById = $indexById
        ByName = $indexByName
        ByNormName = $indexByNormName
    }
}