Skip to content

Commit

Permalink
https://github.com/c-blake/nio/commit/ccd04bc70434dd0f21d19ddbd733241…
Browse files Browse the repository at this point in the history
…e5f93a6fd

details why I view this as busywork more error-prone than valuable.
  • Loading branch information
c-blake committed Dec 15, 2024
1 parent 4786856 commit 9966065
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 16 deletions.
1 change: 1 addition & 0 deletions adix/althash.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
## hashes or `a` alone can similarly mislead. TLDR, want >=2 "summary numbers"
## not one & whole curves are best.

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import std/hashes, bitop # For the Hash type and system `hash()`es
export Hash, `!$`, hash

Expand Down
1 change: 1 addition & 0 deletions adix/amoft.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
## for i in 0..<500: amo.inc i, i # Not v.skewed => not v.accurate
## for (i, c) in amo.mostCommon(5): echo i, " ", c

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import std/[hashes, heapqueue, tables, algorithm]
type
CtMnSketch*[K,C] = object ## CountMinSketch over hashable `K` & counters `C`.
Expand Down
1 change: 1 addition & 0 deletions adix/bitop.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## This is a reimplementation of some things we need from bitops which has CT
## trouble due to importc's. (I feel it's a better naming/factoring, too).
{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1

proc ceilPow2*(x: int): int {.noSideEffect, inline.} =
## Returns ``x`` rounded up to the nearest power of two. <= 0 get 1.
Expand Down
1 change: 1 addition & 0 deletions adix/bltab.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Bits for values and the sentinel key default to 0. `BLTab` otherwise tries to
## be similar to hash variants of multisets.

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import althash, sequint
when not declared(stderr): import std/assertions
type
Expand Down
1 change: 1 addition & 0 deletions adix/btree.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
## Nim TODOs incl: make easy to include inside other generic types, add easy
## HashSet & Table use in terms of this lower-level core, run-tm ->CT errs, do
## GC'd&memfiles Ln variants, do distinct int `Ln` for ovrld/figure out exports.
{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
when not declared(stderr): import std/syncio

proc orderFit*(target, wtSz, ixSz, obSz, lnSz: int): int =
Expand Down
1 change: 1 addition & 0 deletions adix/cumsum.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import adix/cpuCT

proc `[]`[C, W](h: ptr UncheckedArray[C], i: W): var C {.inline.} =
Expand Down
1 change: 1 addition & 0 deletions adix/ditab.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
## under another term like "direct indexing". `K` below must have an available
## conversion to ``int``. Duplicate keys cannot be allowed for this one.

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import althash, sequint, topk; export topk.TopKOrder
when not declared(assert): import std/assertions
type
Expand Down
1 change: 1 addition & 0 deletions adix/lghisto.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
## Bollinger Band style smooths. Second, floating point weights for EWMA-like
## decaying memory are not possible since FP arithmetic kind of breaks BISTs.

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
when not declared(addFloat): import std/formatfloat
import adix/bist, std/math
type
Expand Down
7 changes: 4 additions & 3 deletions adix/lptabz.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
## `seq[(K,V)]`. 6..8 bits avoids most "double cache misses" for miss
## lookups/inserts. `z=0` works if space matters more than time.

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import althash, memutil, bitop, topk, sequint, std/[strutils, memfiles]
export Hash, sequint, topk.TopKOrder
when not declared(assert): import std/[assertions, objectdollar]
Expand Down Expand Up @@ -479,7 +480,7 @@ proc setCap*[K,V,Z;z:static int](t: var LPTabz[K,V,Z,z]; newSize = -1) =
if t.rehash: t.salt = getSalt(old[0].addr)
swap(t.data, old)
when Z is K:
var hc: Hash
var hc = 0.Hash
if K(z) != K(0):
for i in 0 ..< t.getCap: t.unUse(i, false)
for cell in old.mitems:
Expand All @@ -504,7 +505,7 @@ proc setCap*[K,V,Z;z:static int](t: var LPTabz[K,V,Z,z]; newSize = -1) =
template getPut(t, i, key, present, missing: untyped): untyped =
mixin rawPut1, rawPut2, tooFull, getCap, init, setCap
if t.getCap == 0: t.init
var hc, d, newSize: Hash
var hc, d, newSize: Hash = 0
var i = t.rawGet(key, hc, d)
if i < 0:
var j = t.rawPut1(-1 - i, d)
Expand Down Expand Up @@ -701,7 +702,7 @@ proc editKey*[K,V,Z;z:static int](t: var LPTabz[K,V,Z,z]; old, new: K) =
t.data[k].key = new
var hc, d: Hash
let j = t.rawGetDeep(new, hc, d) #Allow `new` to be a dup key
var newSize: int
var newSize = 0
if t.tooFull(d, newSize):
t.setCap newSize #`new` already in `data`; setCap does rest
else: #else point-edit new key index into table
Expand Down
1 change: 1 addition & 0 deletions adix/mvstat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## equivalents but has precise rather than infinite memory which can be nice.
## I.e., it can perfectly "forget" a large spike when it leaves a window.

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
when not declared(addFloat): import std/objectdollar
from std/math import sqrt, sum, `^`
from std/strutils import formatFloat, ffDefault
Expand Down
3 changes: 1 addition & 2 deletions adix/nim.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
path=".."
warning[Uninit]:off
warning[ProveInit]:off
warning[Uninit]:off warning[ProveInit]:off # Should be verbosity:2, not 1
1 change: 1 addition & 0 deletions adix/nsort.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
## also needs inverse transforms on the final pass & current xforms are already
## cheap compared to L2 or worse bandwidth costs. So, 5-20% boost, I'd guess.)

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
when not declared(stdout): import std/syncio
import adix/[cpuCT, cumsum], std/[bitops, math, algorithm]
when defined(cpuPrefetch): import cligen/prefetch # Keep cligen a soft-dep
Expand Down
6 changes: 4 additions & 2 deletions adix/oats.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import std/hashes, adix/[bitop, topk]; export topk.TopKOrder
type # More adaptable than Nim std/sets|tables (named ROats|VROats here)
Oat*[K, Q] = concept t # Base Concept: Open-Addressed Table
Expand Down Expand Up @@ -67,6 +68,7 @@ proc oatSlot*[K,Q](t: Oat[K,Q]; q: Q; h: Hash; d: var Hash): int =

proc tooFull*[K,Q](t: Oat[K,Q]; d: int; newSize: var int): bool =
#-> user proc w/some provided default BUT there's a circular dep through `len`
newSize = 0
let sLen=t.len # Could be a cap-long loop
if sLen + 1 + 1 > t.cap: # Call setCap pre-put? +1 new, +1 free
newSize = t.cap shl 1; return true
Expand All @@ -81,7 +83,7 @@ proc setCap*[K,Q](t: var ROat[K,Q]; newSize = -1) =
else: oatSlots(max(newSize, t.len), 1) # max blocks over-shrink
if newSz == t.cap and newSize == -1: return
var ns = t.newOfCap newSz
var d: int
var d = 0
for i in 0 ..< t.cap:
if t.used i:
let q = t.key i
Expand All @@ -90,7 +92,7 @@ proc setCap*[K,Q](t: var ROat[K,Q]; newSize = -1) =
t.setNew ns

template upSert*[K,Q](t: var Oat[K,Q], q, i, UP, SERT) =
var d, newSize: Hash
var newSize {.noinit.}, d: Hash
let h = q.hash
var i = oatSlot(t, q, h, d)
if i >= 0: UP
Expand Down
1 change: 1 addition & 0 deletions adix/sequint.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# few use (since impls are just not handy or may be slow). Thus it is not a bad
# choice for Nim stdlib inclusion, especially with per CPU speed forks.

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import bitop
const iBit = 8 * sizeof(int)
const iShf = lgPow2(iBit)
Expand Down
1 change: 1 addition & 0 deletions adix/tdigest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
## adapt my B-Tree to speed up the idea. { tDig is also very involved - folks
## just *intuit* histo(ln(x)), but that is a more subjective critique. }

{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
when not declared(addFloat): import std/formatfloat
import std/[math, algorithm]
type
Expand Down
3 changes: 2 additions & 1 deletion adix/topk.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{.warning[Uninit]:off, warning[ProveInit]:off.} # Should be verbosity:2, not 1
import std/[random, algorithm] # quickwit.io/blog/top-k-complexity explains BUT
type #..NOTE heap [θO](n*lg k) &this θ(n),O(n*lg k).
Partn* = enum last, ran #XXX Tukey's 9th | median-of-medians | PDQ?
Expand All @@ -16,7 +17,7 @@ proc initTopK*[T](k=10, partn=last): TopK[T] =
## .. code-block:: nim
## var t = initTopK(); for e in 1..99: t.push e
## for e in t: echo e
result.i = -1; result.k = k; result.partn = partn; result.first = true
result = TopK[T](i: -1, k: k, partn: partn, first: true)
when supportsCopyMem(T) and declared newSeqUninit:
result.s = newSeqUninit[T](2*k); result.s.setLen 0

Expand Down
1 change: 1 addition & 0 deletions tests/nim.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
path=".."
path="../adix"
path="../../cg" # cligen
warning[Uninit]:off warning[ProveInit]:off # Should be verbosity:2, not 1
2 changes: 1 addition & 1 deletion tests/ucl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ proc incFailed(h: var Counts, ms: MSlice): bool =
proc ucl(size=9999, dSize=81920, tm=false) =
## Count unique & total lines on `stdin`. <256B long; <16 MiB unique data.
let t0 = if tm: epochTime() else: 0.0
var h: Counts; h.setCap size # pre-size table & data
var h=Counts(); h.setCap size # pre-size table & data
s.setLen dSize; s.setLen 1
var nTot = 0
block IO:
Expand Down
8 changes: 4 additions & 4 deletions tests/wf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ proc `<`(a, b: Word): bool {.inline.} = # for topk.push
if c == 0: a.len < b.len else: c < 0

proc `$`(w: Word): string = # for output
result.setLen w.len
copyMem result[0].addr, w.mem, w.len
result = newString(w.len)
copyMem result.cstring, w.mem, w.len

when defined(benhoyt): # Ben Hoyt definition of "words"
iterator lowCaseWords(ms: MSlice): Word =
var wd, n: int
var wd, n: int = 0
for i, ch in ms:
if ch in {'A'..'Z'}: # `tr A-Z a-z` preprocess to avoid
ms[i] = char(ord(ch) + 32) # needs MAP_PRIVATE
Expand All @@ -60,7 +60,7 @@ when defined(benhoyt): # Ben Hoyt definition of "words"
if n > 0: yield initWord(wd, n) # any final word
else: # Knuth-McIlroy definition of "words"
iterator lowCaseWords(ms: MSlice): Word =
var wd, n: int
var wd, n: int = 0
for i, ch in ms:
if ch in {'a'..'z'}: # in-word ch
if n == 0: wd = (ms.mem +! i) -! mf.mem
Expand Down
2 changes: 1 addition & 1 deletion tests/wfr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ proc wfr(n=10, count=false,Norm=false, size=9999,dSize=81920, tm=false, Dlm="")=
## Histogram words on `stdin`. <128 MiB unique data; <32B long; <4 GiCount.
let sep = initSep(if Dlm.len != 0: Dlm else: d)
let t0 = if tm: epochTime() else: 0.0
var h: Counts; h.setCap size # pre-size table & data
var h=Counts(); h.setCap size # pre-size table & data
s.setLen dSize; s.setLen 0
var nTot = 0
block IO:
Expand Down
2 changes: 1 addition & 1 deletion tests/wu.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ proc wu(size=9999,dSize=81920, tm=false, Dlm="") =
## Count unique & total words on `stdin`. <32B long; <128 MiB unique data.
let sep = initSep(if Dlm.len != 0: Dlm else: d)
let t0 = if tm: epochTime() else: 0.0
var h: Counts; h.setCap size # pre-size table & data
var h=Counts(); h.setCap size # pre-size table & data
s.setLen dSize; s.setLen 0
var nTot = 0
block IO:
Expand Down
2 changes: 1 addition & 1 deletion util/lfreq.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ proc lfreq(n=10, count=false, size=9999, dSize=81920, recTerm='\n',
## Histogram `stdin` lines (read w/non-memory mapped IO to be pipe friendly).
## Limits: <4 GiB unique data; <16 KiB lines; <4 GiCount.
let t0 = if tm: epochTime() else: 0.0
var h: Counts; h.setCap size # pre-size table & data
var h=Counts(); h.setCap size # pre-size table & data
s.setLen dSize; s.setLen 0
var nTot = 0
block IO:
Expand Down
1 change: 1 addition & 0 deletions util/nim.cfg
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
path=".."
warning[Uninit]:off warning[ProveInit]:off # Should be verbosity:2, not 1

0 comments on commit 9966065

Please sign in to comment.