Ignore:
Timestamp:
Dec 27, 2014, 8:50:24 PM (5 years ago)
Author:
cameron
Message:

Clean up default value processing for enumerated properties; uset_popcount added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/charsetcompiler/UCD/unicode_set.py

    r4191 r4365  
    160160   it.advance(quad_no)
    161161   return (it.get_quad() & quad_val) != 0
    162  
     162
     163def uset_popcount(s):
     164    popcount = 0
     165    it = Uset_Iterator(s)
     166    while not it.at_end():
     167        (runtype, n) = it.current_run()
     168        if runtype == Empty:
     169            it.advance(n)
     170        elif runtype == Full:
     171            popcount += n * quad_bits
     172            it.advance(n)
     173        else:
     174            popcount += popcount_quad(it.get_quad)
     175            it.advance(1)
     176    return popcount
     177
     178def popcount_quad(q):
     179    c = 0
     180    while q != 0:
     181        q = q & (q - 1) # clear low bit
     182        c += 1
     183    return c
     184
    163185def uset_complement (s):
    164186   assert s.quad_count == UnicodeQuadCount
     
    178200            it.advance(1)
    179201   return iset
    180 
    181202
    182203def uset_intersection (s1, s2):
Note: See TracChangeset for help on using the changeset viewer.