(sentinels: ReadonlyArray<SchemaAST.Sentinel>)
| 2220 | } |
| 2221 | |
| 2222 | function sentinelSetHash(sentinels: ReadonlyArray<SchemaAST.Sentinel>): number { |
| 2223 | const sorted = [...sentinels].sort((a, b) => { |
| 2224 | const an = typeof a.key === "number" |
| 2225 | const bn = typeof b.key === "number" |
| 2226 | if (an !== bn) return an ? -1 : 1 |
| 2227 | if (an) return (a.key as number) - (b.key as number) |
| 2228 | return Bytes.Order(utf8Encode.encode(a.key as string), utf8Encode.encode(b.key as string)) |
| 2229 | }) |
| 2230 | const out: Array<number> = [] |
| 2231 | for (const sentinel of sorted) { |
| 2232 | const keyBytes = utf8Encode.encode(String(sentinel.key)) |
| 2233 | out.push(typeof sentinel.key === "number" ? 0 : 1) |
| 2234 | pushU32(out, keyBytes.length) |
| 2235 | pushBytes(out, keyBytes) |
| 2236 | const literal = sentinel.literal |
| 2237 | const valueBytes = utf8Encode.encode(sentinelLiteralString(literal)) |
| 2238 | out.push(sentinelLiteralKind(literal)) |
| 2239 | pushU32(out, valueBytes.length) |
| 2240 | pushBytes(out, valueBytes) |
| 2241 | } |
| 2242 | return fnv32(out) |
| 2243 | } |
| 2244 | |
| 2245 | function sentinelLiteralKind(literal: SchemaAST.LiteralValue | symbol): number { |
| 2246 | switch (typeof literal) { |
no test coverage detected