summary refs log blame commit diff stats
path: root/lib/system/sets.nim
blob: 103c8d343ebe28f0eb661b6908ce9733698158f8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

 
                                  
                                         







                                                   
                                    
 
 
                                                                 
           
            
                                      
                      
                                                                     
               
 
                
                                          
             
#
#
#            Nim's Runtime Library
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# set handling

type
  NimSet = array[0..4*2048-1, uint8]


proc cardSet(s: NimSet, len: int): int {.compilerproc, inline.} =
  var i = 0
  result = 0
  when defined(x86) or defined(amd64):
    while i < len - 8:
      inc(result, countBits64((cast[ptr uint64](s[i].unsafeAddr))[]))
      inc(i, 8)

  while i < len:
    inc(result, countBits32(uint32(s[i])))
    inc(i, 1)