MCPcopy Create free account
hub / github.com/Effect-TS/effect / sentinelSetHash

Function sentinelSetHash

packages/effect/src/encoding/SchemaBinary.ts:2222–2243  ·  view source on GitHub ↗
(sentinels: ReadonlyArray<SchemaAST.Sentinel>)

Source from the content-addressed store, hash-verified

2220}
2221
2222function 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
2245function sentinelLiteralKind(literal: SchemaAST.LiteralValue | symbol): number {
2246 switch (typeof literal) {

Callers 1

compileUnionFunction · 0.85

Calls 8

pushU32Function · 0.85
pushBytesFunction · 0.85
sentinelLiteralStringFunction · 0.85
sentinelLiteralKindFunction · 0.85
fnv32Function · 0.85
encodeMethod · 0.80
pushMethod · 0.65
StringFunction · 0.50

Tested by

no test coverage detected