However, this fix won't take effect until a compiler bug (#4448) is fixed. Until then, the codebase functions identically to
how it did before this commit (calls to clear() fail to compile for Table/OrderedTable/CountTable as the argument is
immutable).
The record tuples used in CountData.data don't contain an 'hcode' member,
unlike Table and OrderedTable, causing the existing clearImpl() implementation
to break when attempting to assign to t.data[i].hcode.
* With previous code, the compiler deduced that equalsImpl may raise
a KeyError. While this could only actually happen in a nasty
multi-threaded environment, I fixed the code so that it will never happen.
Just in case as they are said not overloadable. No deprecation because this is during a PR: those procs didn't exist before.
Also update comment due to failed optimization attempt using copyMem() for POD datatypes.
Better bounds checking. Tried to make it and documentation comply with the conflicting style guides.
Added example of usage at the top of the module as well as warnings on usage.
Also fix the back() and internal englishOrdinal() proc from previous commit.
Added {.discardable.} pragma for .pop(), when calling only for it's side effects.
Sprinkled some unlikely() for optimization.
Some new tests reflecting those changes.
Now queues support indexing, front() and back() operations and pairs iteration.
Also modernized some of the code to use newer Nim features.
Added the "add()" alias to "enqueue()", per nim's conventions (also fits better with pop())
This fixes the (potential) multi-evaluation of the sequence parameter in
foldl() and foldr().
It also adds a foldl() version which gets a start parameter. This allows
for creating a result with a different type than the elements of the
sequence.
Fixes issue with CountTableRef and getOrDefault:
```{nimrod}
import tables
proc main() =
const testKey = "TESTKEY"
let t: CountTableRef[string] = newCountTable[string]()
# Before, does not compile with error message:
#test_counttable.nim(7, 43) template/generic instantiation from here
#lib/pure/collections/tables.nim(117, 21) template/generic instantiation from here
#lib/pure/collections/tableimpl.nim(32, 27) Error: undeclared field: 'hcode'
echo "Count of " & testKey & " is " & $t.getOrDefault(testKey)
t.inc(testKey,3)
echo "Count of " & testKey & " is " & $t.getOrDefault(testKey)
when isMainModule:
main()
```
Previously, `getOrDefault` for CountTableRef objects was calling the
`getOrDefaultImpl` template, which used the t.data.hcode object -
assuming a Table or similar object. Because CountTableRef didn't have
an hcode in its data tuples, this wouldn't compile. Changed to be the
same as `CountTable#getOrDefault`.