summary refs log tree commit diff stats
path: root/koch.nim
Commit message (Expand)AuthorAgeFilesLines
...
* | Merge branch 'devel' into araq-miscAraq2018-08-131-1/+2
|\ \
| * | Clarify usage of "Test" argument in Koch (#8613)Naveen Arunachalam2018-08-121-1/+2
* | | build Nimble with --nilseqs:on until Nimble is fixedAraq2018-08-131-2/+2
|/ /
* | make 'koch xz' enforce a clean 'git diff'; fixes #7292Araq2018-08-041-0/+8
* | fixes #8419 fixes #8420 ; workaround #6071 workaround nim-lang/website#98 (#8...Timothee Cour2018-07-301-0/+1
* | readded -d:debug flagArne Döring2018-06-261-1/+1
* | make basic debugging possibleArne Döring2018-06-261-1/+1
* | nimpretty: proper command line handling; added tests; travis ensures these st...Andreas Rumpf2018-06-191-5/+3
* | remove hardly used TimeMachine featureAndreas Rumpf2018-05-061-1/+0
* | make Nimble not crash after the refactoringAndreas Rumpf2018-05-051-1/+1
* | Fix lists of paths in posix environment (#7034)Dennis Felsing2018-01-081-2/+2
* | Faster nimgrep (#6983)Mathias Stearn2018-01-031-1/+1
* | Prep for tester parallel: private nimcache for each test (#6937)Mathias Stearn2017-12-181-1/+1
* | koch temp uses '-d:debug'Andreas Rumpf2017-11-141-2/+2
* | made nimresolve part of the compilerAndreas Rumpf2017-10-291-1/+1
* | Use findNim() in koch temp() (#6592)Stefan Rakel2017-10-251-1/+2
* | implemented new experimental scriptable import mechanismAndreas Rumpf2017-10-011-0/+3
* | fixes #6028Araq2017-09-041-1/+2
* | moved winrelease to its own tool to fix #6147Araq2017-09-031-41/+44
* | added koch xtemp command for easier compiler developmentAraq2017-06-081-0/+12
* | fixes 'koch winrelease'Araq2017-05-181-22/+10
* | niminst: add missing nimsuggest tool; small koch.nim cleanupAraq2017-05-171-7/+0
* | koch: build release version of nimbleAndreas Rumpf2017-04-261-2/+2
* | koch: cleanup its help output, remove cruftAraq2017-03-211-18/+14
|/
* koch: vcc is also built with 'koch tools'Araq2017-03-211-1/+5
* koch: better valgrind supportAndreas Rumpf2017-03-171-5/+19
* Merge branch 'devel' into faster-nimsuggestAndreas Rumpf2017-03-141-0/+9
|\
| * valgrind support for nimAndreas Rumpf2017-03-141-0/+9
* | nimsuggest: more precise cursor trackingAraq2017-03-091-4/+4
|/
* finish tool can use 'nimgrab' tool to download the mingw versionAraq2017-02-261-0/+3
* koch: don't build downloader tool, it is not readyaraq2017-02-151-2/+3
* koch: boot use hostOs&hostCpu specific nimcacheAndreas Rumpf2017-02-071-1/+2
* downloader tool needs to use httpsAndreas Rumpf2017-02-071-1/+1
* koch.nim: don't commit after 1amAndreas Rumpf2017-02-071-2/+2
* disable NSIS installers, ship with downloader.exe insteadAraq2017-02-071-2/+7
* koch.nim: winrelease without nasty batch filesAraq2017-02-071-3/+58
* add 'koch nimsuggest' command for consistencyAndreas Rumpf2017-01-101-0/+1
* use os.copyDir, not your own broken implementation of itAndreas Rumpf2017-01-101-9/+0
* happy new yearAraq2017-01-071-2/+2
* koch.nim: critical fix for the tar.xz installationsAndreas Rumpf2017-01-071-14/+18
* koch and nims updatesAraq2017-01-061-1/+1
* koch.nim: remove old bin/nimblepkg/*.nim files for nimble installationAndreas Rumpf2017-01-041-0/+4
* koch.nim: don't use --git-dir; produces weird resultsAraq2017-01-031-8/+10
* koch.nim: use new nimble branch setupAraq2017-01-031-34/+24
* support: koch supports 'nimble' vs 'nimble --latest'Andreas Rumpf2016-12-281-13/+24
* 'koch temp --option' passes options to the compiler compilation itselfAndreas Rumpf2016-11-181-2/+17
* nimsuggest is now in tools/Andreas Rumpf2016-11-011-1/+1
* koch improvements; implemented 'koch pushcsources'Araq2016-11-011-10/+43
* touch koch.nim to trigger CI build (4th)Araq2016-11-011-1/+0
* touch koch.nim to trigger CI build (3rd)Araq2016-10-311-0/+1
lass="p">: pointer, size: int): Hash = ## hashes an array of bytes of size `size` var h: Hash = 0 when defined(js): var p: cstring asm """`p` = `Data`;""" else: var p = cast[cstring](data) var i = 0 var s = size while s > 0: h = h !& ord(p[i]) inc(i) dec(s) result = !$h when defined(js): var objectID = 0 proc hash*(x: pointer): Hash {.inline.} = ## efficient hashing of pointers when defined(js): asm """ if (typeof `x` == "object") { if ("_NimID" in `x`) `result` = `x`["_NimID"]; else { `result` = ++`objectID`; `x`["_NimID"] = `result`; } } """ else: result = (cast[Hash](x)) shr 3 # skip the alignment when not defined(booting): proc hash*[T: proc](x: T): Hash {.inline.} = ## efficient hashing of proc vars; closures are supported too. when T is "closure": result = hash(rawProc(x)) !& hash(rawEnv(x)) else: result = hash(pointer(x)) proc hash*(x: int): Hash {.inline.} = ## efficient hashing of integers result = x proc hash*(x: int64): Hash {.inline.} = ## efficient hashing of int64 integers result = toU32(x) proc hash*(x: char): Hash {.inline.} = ## efficient hashing of characters result = ord(x) proc hash*[T: Ordinal](x: T): Hash {.inline.} = ## efficient hashing of other ordinal types (e.g., enums) result = ord(x) proc hash*(x: string): Hash = ## efficient hashing of strings var h: Hash = 0 for i in 0..x.len-1: h = h !& ord(x[i]) result = !$h proc hash*(sBuf: string, sPos, ePos: int): Hash = ## efficient hashing of a string buffer, from starting ## position `sPos` to ending position `ePos` ## ## ``hash(myStr, 0, myStr.high)`` is equivalent to ``hash(myStr)`` var h: Hash = 0 for i in sPos..ePos: h = h !& ord(sBuf[i]) result = !$h proc hashIgnoreStyle*(x: string): Hash = ## efficient hashing of strings; style is ignored var h: Hash = 0 var i = 0 let xLen = x.len while i < xLen: var c = x[i] if c == '_': inc(i) elif isMagicIdentSeparatorRune(cstring(x), i): inc(i, magicIdentSeparatorRuneByteWidth) else: if c in {'A'..'Z'}: c = chr(ord(c) + (ord('a') - ord('A'))) # toLower() h = h !& ord(c) inc(i) result = !$h proc hashIgnoreStyle*(sBuf: string, sPos, ePos: int): Hash = ## efficient hashing of a string buffer, from starting ## position `sPos` to ending position `ePos`; style is ignored ## ## ``hashIgnoreStyle(myBuf, 0, myBuf.high)`` is equivalent ## to ``hashIgnoreStyle(myBuf)`` var h: Hash = 0 var i = sPos while i <= ePos: var c = sBuf[i] if c == '_': inc(i) elif isMagicIdentSeparatorRune(cstring(sBuf), i): inc(i, magicIdentSeparatorRuneByteWidth) else: if c in {'A'..'Z'}: c = chr(ord(c) + (ord('a') - ord('A'))) # toLower() h = h !& ord(c) inc(i) result = !$h proc hashIgnoreCase*(x: string): Hash = ## efficient hashing of strings; case is ignored var h: Hash = 0 for i in 0..x.len-1: var c = x[i] if c in {'A'..'Z'}: c = chr(ord(c) + (ord('a') - ord('A'))) # toLower() h = h !& ord(c) result = !$h proc hashIgnoreCase*(sBuf: string, sPos, ePos: int): Hash = ## efficient hashing of a string buffer, from starting ## position `sPos` to ending position `ePos`; case is ignored ## ## ``hashIgnoreCase(myBuf, 0, myBuf.high)`` is equivalent ## to ``hashIgnoreCase(myBuf)`` var h: Hash = 0 for i in sPos..ePos: var c = sBuf[i] if c in {'A'..'Z'}: c = chr(ord(c) + (ord('a') - ord('A'))) # toLower() h = h !& ord(c) result = !$h proc hash*(x: float): Hash {.inline.} = ## efficient hashing of floats. var y = x + 1.0 result = cast[ptr Hash](addr(y))[] # Forward declarations before methods that hash containers. This allows # containers to contain other containers proc hash*[A](x: openArray[A]): Hash proc hash*[A](x: set[A]): Hash proc hash*[T: tuple](x: T): Hash = ## efficient hashing of tuples. for f in fields(x): result = result !& hash(f) result = !$result proc hash*[A](x: openArray[A]): Hash = ## efficient hashing of arrays and sequences. for it in items(x): result = result !& hash(it) result = !$result proc hash*[A](aBuf: openArray[A], sPos, ePos: int): Hash = ## efficient hashing of portions of arrays and sequences. ## ## ``hash(myBuf, 0, myBuf.high)`` is equivalent to ``hash(myBuf)`` for i in sPos..ePos: result = result !& hash(aBuf[i]) result = !$result proc hash*[A](x: set[A]): Hash = ## efficient hashing of sets. for it in items(x): result = result !& hash(it) result = !$result when isMainModule: doAssert( hash("aa bb aaaa1234") == hash("aa bb aaaa1234", 0, 13) ) doAssert( hashIgnoreCase("aa bb aaaa1234") == hash("aa bb aaaa1234") ) doAssert( hashIgnoreStyle("aa bb aaaa1234") == hashIgnoreCase("aa bb aaaa1234") ) let xx = @['H','e','l','l','o'] let ss = "Hello" doAssert( hash(xx) == hash(ss) ) doAssert( hash(xx) == hash(xx, 0, xx.high) ) doAssert( hash(ss) == hash(ss, 0, ss.high) )