Hi **Araq**, could please elaborate "string case is O(1)" a bit more?
O(1) means hashtables to me, hence I presume something along these lines (not a
final version):
import tables
import hashes
proc genTableForEnum[T: enum](): Table[string, T] =
result = initTable[string, T](rightSize(ord(high(T)) - ord(low(T)) + 1))
for i in low(T)..high(T):
# TODO: skip holes in enum
result[$i] = i
proc parseEnum*[T: enum](s: string): T =
proc hash(s: string): Hash =
# BUG: you can't mixin new Hash function into table
result = hashIgnoreStyle(s)
const enumTable = genTableForEnum[T]()
result = enumTable[s]
This one looks really efficient except hash table is bigger than it could have
been. I couldn't make tables module to work because I couldn't replace a
standard hash with hashIgnoreStyle. I guess tables needs "mixin hash" is
several places. Module gentabs did work, but it is deprecated.
Let me know your thoughts.