sets.nim 657 B

1234567891011121314151617181920212223242526272829
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2012 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. # set handling
  10. type
  11. NimSet = array[0..8192-1, uint8]
  12. proc cardSetImpl(s: openArray[uint8], len: int): int {.inline.} =
  13. var i = 0
  14. result = 0
  15. when defined(x86) or defined(amd64):
  16. while i < len - 8:
  17. inc(result, countBits64((cast[ptr uint64](s[i].unsafeAddr))[]))
  18. inc(i, 8)
  19. while i < len:
  20. inc(result, countBits32(uint32(s[i])))
  21. inc(i, 1)
  22. proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
  23. result = cardSetImpl(s, len)