sets.nim 667 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. proc cardSetImpl(s: ptr UncheckedArray[uint8], len: int): int {.inline.} =
  11. var i = 0
  12. result = 0
  13. var num = 0'u64
  14. when defined(x86) or defined(amd64):
  15. while i < len - 8:
  16. copyMem(addr num, addr s[i], 8)
  17. inc(result, countBits64(num))
  18. inc(i, 8)
  19. while i < len:
  20. inc(result, countBits32(uint32(s[i])))
  21. inc(i, 1)
  22. proc cardSet(s: ptr UncheckedArray[uint8], len: int): int {.compilerproc, inline.} =
  23. result = cardSetImpl(s, len)