You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

bitmap.go 391 B

1234567891011121314151617181920212223242526272829
  1. package bitmap
  2. type Bitmap64 uint64
  3. func (b *Bitmap64) Set(index int, val bool) {
  4. if val {
  5. *b |= 1 << index
  6. } else {
  7. *b &= ^(1 << index)
  8. }
  9. }
  10. func (b *Bitmap64) Get(index int) bool {
  11. return (*b & (1 << index)) > 0
  12. }
  13. func (b *Bitmap64) Or(other *Bitmap64) {
  14. *b |= *other
  15. }
  16. func (b *Bitmap64) Weight() int {
  17. v := *b
  18. cnt := 0
  19. for v > 0 {
  20. cnt++
  21. v &= (v - 1)
  22. }
  23. return cnt
  24. }