sets.nim 562 B

123456789101112131415161718192021222324252627
  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..4*2048-1, uint8]
  12. proc cardSet(s: NimSet, len: int): int {.compilerproc, 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)