Dropped 'T' from types
This commit is contained in:
parent
88e849078f
commit
9764ba933b
6 changed files with 41 additions and 41 deletions
|
|
@ -842,7 +842,7 @@ type
|
||||||
data*: TIdNodePairSeq
|
data*: TIdNodePairSeq
|
||||||
|
|
||||||
TNodePair* = object
|
TNodePair* = object
|
||||||
h*: THash # because it is expensive to compute!
|
h*: Hash # because it is expensive to compute!
|
||||||
key*: PNode
|
key*: PNode
|
||||||
val*: int
|
val*: int
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
import
|
import
|
||||||
ast, hashes, intsets, strutils, options, msgs, ropes, idents, rodutils
|
ast, hashes, intsets, strutils, options, msgs, ropes, idents, rodutils
|
||||||
|
|
||||||
proc hashNode*(p: RootRef): THash
|
proc hashNode*(p: RootRef): Hash
|
||||||
proc treeToYaml*(n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope
|
proc treeToYaml*(n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope
|
||||||
# Convert a tree into its YAML representation; this is used by the
|
# Convert a tree into its YAML representation; this is used by the
|
||||||
# YAML code generator and it is invaluable for debugging purposes.
|
# YAML code generator and it is invaluable for debugging purposes.
|
||||||
|
|
@ -49,7 +49,7 @@ proc strTableGet*(t: TStrTable, name: PIdent): PSym
|
||||||
|
|
||||||
type
|
type
|
||||||
TTabIter*{.final.} = object # consider all fields here private
|
TTabIter*{.final.} = object # consider all fields here private
|
||||||
h*: THash # current hash
|
h*: Hash # current hash
|
||||||
|
|
||||||
proc initTabIter*(ti: var TTabIter, tab: TStrTable): PSym
|
proc initTabIter*(ti: var TTabIter, tab: TStrTable): PSym
|
||||||
proc nextIter*(ti: var TTabIter, tab: TStrTable): PSym
|
proc nextIter*(ti: var TTabIter, tab: TStrTable): PSym
|
||||||
|
|
@ -65,7 +65,7 @@ proc nextIter*(ti: var TTabIter, tab: TStrTable): PSym
|
||||||
|
|
||||||
type
|
type
|
||||||
TIdentIter*{.final.} = object # iterator over all syms with same identifier
|
TIdentIter*{.final.} = object # iterator over all syms with same identifier
|
||||||
h*: THash # current hash
|
h*: Hash # current hash
|
||||||
name*: PIdent
|
name*: PIdent
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ proc getSymFromList*(list: PNode, ident: PIdent, start: int = 0): PSym
|
||||||
proc lookupInRecord*(n: PNode, field: PIdent): PSym
|
proc lookupInRecord*(n: PNode, field: PIdent): PSym
|
||||||
proc getModule*(s: PSym): PSym
|
proc getModule*(s: PSym): PSym
|
||||||
proc mustRehash*(length, counter: int): bool
|
proc mustRehash*(length, counter: int): bool
|
||||||
proc nextTry*(h, maxHash: THash): THash {.inline.}
|
proc nextTry*(h, maxHash: Hash): Hash {.inline.}
|
||||||
|
|
||||||
# ------------- table[int, int] ---------------------------------------------
|
# ------------- table[int, int] ---------------------------------------------
|
||||||
const
|
const
|
||||||
|
|
@ -196,7 +196,7 @@ proc getSymFromList(list: PNode, ident: PIdent, start: int = 0): PSym =
|
||||||
else: internalError(list.info, "getSymFromList")
|
else: internalError(list.info, "getSymFromList")
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
proc hashNode(p: RootRef): THash =
|
proc hashNode(p: RootRef): Hash =
|
||||||
result = hash(cast[pointer](p))
|
result = hash(cast[pointer](p))
|
||||||
|
|
||||||
proc mustRehash(length, counter: int): bool =
|
proc mustRehash(length, counter: int): bool =
|
||||||
|
|
@ -466,7 +466,7 @@ proc debug(n: PNode) =
|
||||||
const
|
const
|
||||||
EmptySeq = @[]
|
EmptySeq = @[]
|
||||||
|
|
||||||
proc nextTry(h, maxHash: THash): THash =
|
proc nextTry(h, maxHash: Hash): Hash =
|
||||||
result = ((5 * h) + 1) and maxHash
|
result = ((5 * h) + 1) and maxHash
|
||||||
# For any initial h in range(maxHash), repeating that maxHash times
|
# For any initial h in range(maxHash), repeating that maxHash times
|
||||||
# generates each int in range(maxHash) exactly once (see any text on
|
# generates each int in range(maxHash) exactly once (see any text on
|
||||||
|
|
@ -474,7 +474,7 @@ proc nextTry(h, maxHash: THash): THash =
|
||||||
|
|
||||||
proc objectSetContains(t: TObjectSet, obj: RootRef): bool =
|
proc objectSetContains(t: TObjectSet, obj: RootRef): bool =
|
||||||
# returns true whether n is in t
|
# returns true whether n is in t
|
||||||
var h: THash = hashNode(obj) and high(t.data) # start with real hash value
|
var h: Hash = hashNode(obj) and high(t.data) # start with real hash value
|
||||||
while t.data[h] != nil:
|
while t.data[h] != nil:
|
||||||
if t.data[h] == obj:
|
if t.data[h] == obj:
|
||||||
return true
|
return true
|
||||||
|
|
@ -482,7 +482,7 @@ proc objectSetContains(t: TObjectSet, obj: RootRef): bool =
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc objectSetRawInsert(data: var TObjectSeq, obj: RootRef) =
|
proc objectSetRawInsert(data: var TObjectSeq, obj: RootRef) =
|
||||||
var h: THash = hashNode(obj) and high(data)
|
var h: Hash = hashNode(obj) and high(data)
|
||||||
while data[h] != nil:
|
while data[h] != nil:
|
||||||
assert(data[h] != obj)
|
assert(data[h] != obj)
|
||||||
h = nextTry(h, high(data))
|
h = nextTry(h, high(data))
|
||||||
|
|
@ -503,7 +503,7 @@ proc objectSetIncl(t: var TObjectSet, obj: RootRef) =
|
||||||
|
|
||||||
proc objectSetContainsOrIncl(t: var TObjectSet, obj: RootRef): bool =
|
proc objectSetContainsOrIncl(t: var TObjectSet, obj: RootRef): bool =
|
||||||
# returns true if obj is already in the string table:
|
# returns true if obj is already in the string table:
|
||||||
var h: THash = hashNode(obj) and high(t.data)
|
var h: Hash = hashNode(obj) and high(t.data)
|
||||||
while true:
|
while true:
|
||||||
var it = t.data[h]
|
var it = t.data[h]
|
||||||
if it == nil: break
|
if it == nil: break
|
||||||
|
|
@ -520,7 +520,7 @@ proc objectSetContainsOrIncl(t: var TObjectSet, obj: RootRef): bool =
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc tableRawGet(t: TTable, key: RootRef): int =
|
proc tableRawGet(t: TTable, key: RootRef): int =
|
||||||
var h: THash = hashNode(key) and high(t.data) # start with real hash value
|
var h: Hash = hashNode(key) and high(t.data) # start with real hash value
|
||||||
while t.data[h].key != nil:
|
while t.data[h].key != nil:
|
||||||
if t.data[h].key == key:
|
if t.data[h].key == key:
|
||||||
return h
|
return h
|
||||||
|
|
@ -529,7 +529,7 @@ proc tableRawGet(t: TTable, key: RootRef): int =
|
||||||
|
|
||||||
proc tableSearch(t: TTable, key, closure: RootRef,
|
proc tableSearch(t: TTable, key, closure: RootRef,
|
||||||
comparator: TCmpProc): RootRef =
|
comparator: TCmpProc): RootRef =
|
||||||
var h: THash = hashNode(key) and high(t.data) # start with real hash value
|
var h: Hash = hashNode(key) and high(t.data) # start with real hash value
|
||||||
while t.data[h].key != nil:
|
while t.data[h].key != nil:
|
||||||
if t.data[h].key == key:
|
if t.data[h].key == key:
|
||||||
if comparator(t.data[h].val, closure):
|
if comparator(t.data[h].val, closure):
|
||||||
|
|
@ -544,7 +544,7 @@ proc tableGet(t: TTable, key: RootRef): RootRef =
|
||||||
else: result = nil
|
else: result = nil
|
||||||
|
|
||||||
proc tableRawInsert(data: var TPairSeq, key, val: RootRef) =
|
proc tableRawInsert(data: var TPairSeq, key, val: RootRef) =
|
||||||
var h: THash = hashNode(key) and high(data)
|
var h: Hash = hashNode(key) and high(data)
|
||||||
while data[h].key != nil:
|
while data[h].key != nil:
|
||||||
assert(data[h].key != key)
|
assert(data[h].key != key)
|
||||||
h = nextTry(h, high(data))
|
h = nextTry(h, high(data))
|
||||||
|
|
@ -569,7 +569,7 @@ proc tablePut(t: var TTable, key, val: RootRef) =
|
||||||
inc(t.counter)
|
inc(t.counter)
|
||||||
|
|
||||||
proc strTableContains(t: TStrTable, n: PSym): bool =
|
proc strTableContains(t: TStrTable, n: PSym): bool =
|
||||||
var h: THash = n.name.h and high(t.data) # start with real hash value
|
var h: Hash = n.name.h and high(t.data) # start with real hash value
|
||||||
while t.data[h] != nil:
|
while t.data[h] != nil:
|
||||||
if (t.data[h] == n):
|
if (t.data[h] == n):
|
||||||
return true
|
return true
|
||||||
|
|
@ -577,7 +577,7 @@ proc strTableContains(t: TStrTable, n: PSym): bool =
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc strTableRawInsert(data: var TSymSeq, n: PSym) =
|
proc strTableRawInsert(data: var TSymSeq, n: PSym) =
|
||||||
var h: THash = n.name.h and high(data)
|
var h: Hash = n.name.h and high(data)
|
||||||
if sfImmediate notin n.flags:
|
if sfImmediate notin n.flags:
|
||||||
# fast path:
|
# fast path:
|
||||||
while data[h] != nil:
|
while data[h] != nil:
|
||||||
|
|
@ -606,7 +606,7 @@ proc strTableRawInsert(data: var TSymSeq, n: PSym) =
|
||||||
|
|
||||||
proc symTabReplaceRaw(data: var TSymSeq, prevSym: PSym, newSym: PSym) =
|
proc symTabReplaceRaw(data: var TSymSeq, prevSym: PSym, newSym: PSym) =
|
||||||
assert prevSym.name.h == newSym.name.h
|
assert prevSym.name.h == newSym.name.h
|
||||||
var h: THash = prevSym.name.h and high(data)
|
var h: Hash = prevSym.name.h and high(data)
|
||||||
while data[h] != nil:
|
while data[h] != nil:
|
||||||
if data[h] == prevSym:
|
if data[h] == prevSym:
|
||||||
data[h] = newSym
|
data[h] = newSym
|
||||||
|
|
@ -640,7 +640,7 @@ proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
|
||||||
# It is essential that `n` is written nevertheless!
|
# It is essential that `n` is written nevertheless!
|
||||||
# This way the newest redefinition is picked by the semantic analyses!
|
# This way the newest redefinition is picked by the semantic analyses!
|
||||||
assert n.name != nil
|
assert n.name != nil
|
||||||
var h: THash = n.name.h and high(t.data)
|
var h: Hash = n.name.h and high(t.data)
|
||||||
var replaceSlot = -1
|
var replaceSlot = -1
|
||||||
while true:
|
while true:
|
||||||
var it = t.data[h]
|
var it = t.data[h]
|
||||||
|
|
@ -666,7 +666,7 @@ proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc strTableGet(t: TStrTable, name: PIdent): PSym =
|
proc strTableGet(t: TStrTable, name: PIdent): PSym =
|
||||||
var h: THash = name.h and high(t.data)
|
var h: Hash = name.h and high(t.data)
|
||||||
while true:
|
while true:
|
||||||
result = t.data[h]
|
result = t.data[h]
|
||||||
if result == nil: break
|
if result == nil: break
|
||||||
|
|
@ -694,7 +694,7 @@ proc nextIdentIter(ti: var TIdentIter, tab: TStrTable): PSym =
|
||||||
|
|
||||||
proc nextIdentExcluding*(ti: var TIdentIter, tab: TStrTable,
|
proc nextIdentExcluding*(ti: var TIdentIter, tab: TStrTable,
|
||||||
excluding: IntSet): PSym =
|
excluding: IntSet): PSym =
|
||||||
var h: THash = ti.h and high(tab.data)
|
var h: Hash = ti.h and high(tab.data)
|
||||||
var start = h
|
var start = h
|
||||||
result = tab.data[h]
|
result = tab.data[h]
|
||||||
while result != nil:
|
while result != nil:
|
||||||
|
|
@ -743,7 +743,7 @@ proc hasEmptySlot(data: TIdPairSeq): bool =
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
proc idTableRawGet(t: TIdTable, key: int): int =
|
proc idTableRawGet(t: TIdTable, key: int): int =
|
||||||
var h: THash
|
var h: Hash
|
||||||
h = key and high(t.data) # start with real hash value
|
h = key and high(t.data) # start with real hash value
|
||||||
while t.data[h].key != nil:
|
while t.data[h].key != nil:
|
||||||
if t.data[h].key.id == key:
|
if t.data[h].key.id == key:
|
||||||
|
|
@ -772,7 +772,7 @@ iterator pairs*(t: TIdTable): tuple[key: int, value: RootRef] =
|
||||||
yield (t.data[i].key.id, t.data[i].val)
|
yield (t.data[i].key.id, t.data[i].val)
|
||||||
|
|
||||||
proc idTableRawInsert(data: var TIdPairSeq, key: PIdObj, val: RootRef) =
|
proc idTableRawInsert(data: var TIdPairSeq, key: PIdObj, val: RootRef) =
|
||||||
var h: THash
|
var h: Hash
|
||||||
h = key.id and high(data)
|
h = key.id and high(data)
|
||||||
while data[h].key != nil:
|
while data[h].key != nil:
|
||||||
assert(data[h].key.id != key.id)
|
assert(data[h].key.id != key.id)
|
||||||
|
|
@ -805,7 +805,7 @@ iterator idTablePairs*(t: TIdTable): tuple[key: PIdObj, val: RootRef] =
|
||||||
if not isNil(t.data[i].key): yield (t.data[i].key, t.data[i].val)
|
if not isNil(t.data[i].key): yield (t.data[i].key, t.data[i].val)
|
||||||
|
|
||||||
proc idNodeTableRawGet(t: TIdNodeTable, key: PIdObj): int =
|
proc idNodeTableRawGet(t: TIdNodeTable, key: PIdObj): int =
|
||||||
var h: THash
|
var h: Hash
|
||||||
h = key.id and high(t.data) # start with real hash value
|
h = key.id and high(t.data) # start with real hash value
|
||||||
while t.data[h].key != nil:
|
while t.data[h].key != nil:
|
||||||
if t.data[h].key.id == key.id:
|
if t.data[h].key.id == key.id:
|
||||||
|
|
@ -824,7 +824,7 @@ proc idNodeTableGetLazy*(t: TIdNodeTable, key: PIdObj): PNode =
|
||||||
result = idNodeTableGet(t, key)
|
result = idNodeTableGet(t, key)
|
||||||
|
|
||||||
proc idNodeTableRawInsert(data: var TIdNodePairSeq, key: PIdObj, val: PNode) =
|
proc idNodeTableRawInsert(data: var TIdNodePairSeq, key: PIdObj, val: PNode) =
|
||||||
var h: THash
|
var h: Hash
|
||||||
h = key.id and high(data)
|
h = key.id and high(data)
|
||||||
while data[h].key != nil:
|
while data[h].key != nil:
|
||||||
assert(data[h].key.id != key.id)
|
assert(data[h].key.id != key.id)
|
||||||
|
|
@ -863,7 +863,7 @@ proc initIITable(x: var TIITable) =
|
||||||
for i in countup(0, StartSize - 1): x.data[i].key = InvalidKey
|
for i in countup(0, StartSize - 1): x.data[i].key = InvalidKey
|
||||||
|
|
||||||
proc iiTableRawGet(t: TIITable, key: int): int =
|
proc iiTableRawGet(t: TIITable, key: int): int =
|
||||||
var h: THash
|
var h: Hash
|
||||||
h = key and high(t.data) # start with real hash value
|
h = key and high(t.data) # start with real hash value
|
||||||
while t.data[h].key != InvalidKey:
|
while t.data[h].key != InvalidKey:
|
||||||
if t.data[h].key == key: return h
|
if t.data[h].key == key: return h
|
||||||
|
|
@ -876,7 +876,7 @@ proc iiTableGet(t: TIITable, key: int): int =
|
||||||
else: result = InvalidKey
|
else: result = InvalidKey
|
||||||
|
|
||||||
proc iiTableRawInsert(data: var TIIPairSeq, key, val: int) =
|
proc iiTableRawInsert(data: var TIIPairSeq, key, val: int) =
|
||||||
var h: THash
|
var h: Hash
|
||||||
h = key and high(data)
|
h = key and high(data)
|
||||||
while data[h].key != InvalidKey:
|
while data[h].key != InvalidKey:
|
||||||
assert(data[h].key != key)
|
assert(data[h].key != key)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import
|
||||||
|
|
||||||
type
|
type
|
||||||
TSections = array[TSymKind, Rope]
|
TSections = array[TSymKind, Rope]
|
||||||
TDocumentor = object of rstgen.TRstGenerator
|
TDocumentor = object of rstgen.RstGenerator
|
||||||
modDesc: Rope # module description
|
modDesc: Rope # module description
|
||||||
id: int # for generating IDs
|
id: int # for generating IDs
|
||||||
toc, section: TSections
|
toc, section: TSections
|
||||||
|
|
@ -29,7 +29,7 @@ type
|
||||||
PDoc* = ref TDocumentor ## Alias to type less.
|
PDoc* = ref TDocumentor ## Alias to type less.
|
||||||
|
|
||||||
proc compilerMsgHandler(filename: string, line, col: int,
|
proc compilerMsgHandler(filename: string, line, col: int,
|
||||||
msgKind: rst.TMsgKind, arg: string) {.procvar.} =
|
msgKind: rst.MsgKind, arg: string) {.procvar.} =
|
||||||
# translate msg kind:
|
# translate msg kind:
|
||||||
var k: msgs.TMsgKind
|
var k: msgs.TMsgKind
|
||||||
case msgKind
|
case msgKind
|
||||||
|
|
@ -53,7 +53,7 @@ proc docgenFindFile(s: string): string {.procvar.} =
|
||||||
|
|
||||||
proc parseRst(text, filename: string,
|
proc parseRst(text, filename: string,
|
||||||
line, column: int, hasToc: var bool,
|
line, column: int, hasToc: var bool,
|
||||||
rstOptions: TRstParseOptions): PRstNode =
|
rstOptions: RstParseOptions): PRstNode =
|
||||||
result = rstParse(text, filename, line, column, hasToc, rstOptions,
|
result = rstParse(text, filename, line, column, hasToc, rstOptions,
|
||||||
docgenFindFile, compilerMsgHandler)
|
docgenFindFile, compilerMsgHandler)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ type
|
||||||
TIdent*{.acyclic.} = object of TIdObj
|
TIdent*{.acyclic.} = object of TIdObj
|
||||||
s*: string
|
s*: string
|
||||||
next*: PIdent # for hash-table chaining
|
next*: PIdent # for hash-table chaining
|
||||||
h*: THash # hash value of s
|
h*: Hash # hash value of s
|
||||||
|
|
||||||
var firstCharIsCS*: bool = true
|
var firstCharIsCS*: bool = true
|
||||||
var buckets*: array[0..4096 * 2 - 1, PIdent]
|
var buckets*: array[0..4096 * 2 - 1, PIdent]
|
||||||
|
|
@ -67,7 +67,7 @@ proc cmpExact(a, b: cstring, blen: int): int =
|
||||||
|
|
||||||
var wordCounter = 1
|
var wordCounter = 1
|
||||||
|
|
||||||
proc getIdent*(identifier: cstring, length: int, h: THash): PIdent =
|
proc getIdent*(identifier: cstring, length: int, h: Hash): PIdent =
|
||||||
var idx = h and high(buckets)
|
var idx = h and high(buckets)
|
||||||
result = buckets[idx]
|
result = buckets[idx]
|
||||||
var last: PIdent = nil
|
var last: PIdent = nil
|
||||||
|
|
@ -101,7 +101,7 @@ proc getIdent*(identifier: string): PIdent =
|
||||||
result = getIdent(cstring(identifier), len(identifier),
|
result = getIdent(cstring(identifier), len(identifier),
|
||||||
hashIgnoreStyle(identifier))
|
hashIgnoreStyle(identifier))
|
||||||
|
|
||||||
proc getIdent*(identifier: string, h: THash): PIdent =
|
proc getIdent*(identifier: string, h: Hash): PIdent =
|
||||||
result = getIdent(cstring(identifier), len(identifier), h)
|
result = getIdent(cstring(identifier), len(identifier), h)
|
||||||
|
|
||||||
proc identEq*(id: PIdent, name: string): bool =
|
proc identEq*(id: PIdent, name: string): bool =
|
||||||
|
|
|
||||||
|
|
@ -671,7 +671,7 @@ proc getCharacter(L: var TLexer, tok: var TToken) =
|
||||||
inc(L.bufpos) # skip '
|
inc(L.bufpos) # skip '
|
||||||
|
|
||||||
proc getSymbol(L: var TLexer, tok: var TToken) =
|
proc getSymbol(L: var TLexer, tok: var TToken) =
|
||||||
var h: THash = 0
|
var h: Hash = 0
|
||||||
var pos = L.bufpos
|
var pos = L.bufpos
|
||||||
var buf = L.buf
|
var buf = L.buf
|
||||||
while true:
|
while true:
|
||||||
|
|
@ -709,7 +709,7 @@ proc getSymbol(L: var TLexer, tok: var TToken) =
|
||||||
tok.tokType = TTokType(tok.ident.id + ord(tkSymbol))
|
tok.tokType = TTokType(tok.ident.id + ord(tkSymbol))
|
||||||
|
|
||||||
proc endOperator(L: var TLexer, tok: var TToken, pos: int,
|
proc endOperator(L: var TLexer, tok: var TToken, pos: int,
|
||||||
hash: THash) {.inline.} =
|
hash: Hash) {.inline.} =
|
||||||
var h = !$hash
|
var h = !$hash
|
||||||
tok.ident = getIdent(addr(L.buf[L.bufpos]), pos - L.bufpos, h)
|
tok.ident = getIdent(addr(L.buf[L.bufpos]), pos - L.bufpos, h)
|
||||||
if (tok.ident.id < oprLow) or (tok.ident.id > oprHigh): tok.tokType = tkOpr
|
if (tok.ident.id < oprLow) or (tok.ident.id > oprHigh): tok.tokType = tkOpr
|
||||||
|
|
@ -719,7 +719,7 @@ proc endOperator(L: var TLexer, tok: var TToken, pos: int,
|
||||||
proc getOperator(L: var TLexer, tok: var TToken) =
|
proc getOperator(L: var TLexer, tok: var TToken) =
|
||||||
var pos = L.bufpos
|
var pos = L.bufpos
|
||||||
var buf = L.buf
|
var buf = L.buf
|
||||||
var h: THash = 0
|
var h: Hash = 0
|
||||||
while true:
|
while true:
|
||||||
var c = buf[pos]
|
var c = buf[pos]
|
||||||
if c notin OpChars: break
|
if c notin OpChars: break
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
import
|
import
|
||||||
hashes, ast, astalgo, types
|
hashes, ast, astalgo, types
|
||||||
|
|
||||||
proc hashTree(n: PNode): THash =
|
proc hashTree(n: PNode): Hash =
|
||||||
if n == nil: return
|
if n == nil: return
|
||||||
result = ord(n.kind)
|
result = ord(n.kind)
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
@ -53,8 +53,8 @@ proc treesEquivalent(a, b: PNode): bool =
|
||||||
result = true
|
result = true
|
||||||
if result: result = sameTypeOrNil(a.typ, b.typ)
|
if result: result = sameTypeOrNil(a.typ, b.typ)
|
||||||
|
|
||||||
proc nodeTableRawGet(t: TNodeTable, k: THash, key: PNode): int =
|
proc nodeTableRawGet(t: TNodeTable, k: Hash, key: PNode): int =
|
||||||
var h: THash = k and high(t.data)
|
var h: Hash = k and high(t.data)
|
||||||
while t.data[h].key != nil:
|
while t.data[h].key != nil:
|
||||||
if (t.data[h].h == k) and treesEquivalent(t.data[h].key, key):
|
if (t.data[h].h == k) and treesEquivalent(t.data[h].key, key):
|
||||||
return h
|
return h
|
||||||
|
|
@ -66,9 +66,9 @@ proc nodeTableGet*(t: TNodeTable, key: PNode): int =
|
||||||
if index >= 0: result = t.data[index].val
|
if index >= 0: result = t.data[index].val
|
||||||
else: result = low(int)
|
else: result = low(int)
|
||||||
|
|
||||||
proc nodeTableRawInsert(data: var TNodePairSeq, k: THash, key: PNode,
|
proc nodeTableRawInsert(data: var TNodePairSeq, k: Hash, key: PNode,
|
||||||
val: int) =
|
val: int) =
|
||||||
var h: THash = k and high(data)
|
var h: Hash = k and high(data)
|
||||||
while data[h].key != nil: h = nextTry(h, high(data))
|
while data[h].key != nil: h = nextTry(h, high(data))
|
||||||
assert(data[h].key == nil)
|
assert(data[h].key == nil)
|
||||||
data[h].h = k
|
data[h].h = k
|
||||||
|
|
@ -77,7 +77,7 @@ proc nodeTableRawInsert(data: var TNodePairSeq, k: THash, key: PNode,
|
||||||
|
|
||||||
proc nodeTablePut*(t: var TNodeTable, key: PNode, val: int) =
|
proc nodeTablePut*(t: var TNodeTable, key: PNode, val: int) =
|
||||||
var n: TNodePairSeq
|
var n: TNodePairSeq
|
||||||
var k: THash = hashTree(key)
|
var k: Hash = hashTree(key)
|
||||||
var index = nodeTableRawGet(t, k, key)
|
var index = nodeTableRawGet(t, k, key)
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
assert(t.data[index].key != nil)
|
assert(t.data[index].key != nil)
|
||||||
|
|
@ -94,7 +94,7 @@ proc nodeTablePut*(t: var TNodeTable, key: PNode, val: int) =
|
||||||
|
|
||||||
proc nodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int =
|
proc nodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int =
|
||||||
var n: TNodePairSeq
|
var n: TNodePairSeq
|
||||||
var k: THash = hashTree(key)
|
var k: Hash = hashTree(key)
|
||||||
var index = nodeTableRawGet(t, k, key)
|
var index = nodeTableRawGet(t, k, key)
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
assert(t.data[index].key != nil)
|
assert(t.data[index].key != nil)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue