github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekamath/bitset_debug_test.go (about)

     1  // Copyright © 2021. All rights reserved.
     2  // Author: Ilya Stroy.
     3  // Contacts: iyuryevich@pm.me, https://github.com/qioalice
     4  // License: https://opensource.org/licenses/MIT
     5  
     6  package ekamath
     7  
     8  import (
     9  	"fmt"
    10  	"strings"
    11  	"unsafe"
    12  )
    13  
    14  func (bs *BitSet) DebugOnesAsSlice(expectedValues uint) []uint {
    15  	ones := make([]uint, 0, Max(expectedValues, _BITSET_MINIMUM_CAPACITY)+1)
    16  	for v, e := bs.NextUp(0); e; v, e = bs.NextUp(v) {
    17  		ones = append(ones, v)
    18  	}
    19  	return ones
    20  }
    21  
    22  func (bs *BitSet) DebugFullDump() {
    23  
    24  	fmt.Printf("Bitset dump of [%x]\n", uintptr(unsafe.Pointer(bs)))
    25  	defer fmt.Printf("End of bitset dump of [%x]\n", uintptr(unsafe.Pointer(bs)))
    26  
    27  	if bs == nil {
    28  		return
    29  	}
    30  
    31  	countOnes := bs.Count()
    32  
    33  	fmt.Printf("\tIs valid:       %t\n", bs.IsValid())
    34  	fmt.Printf("\tChunk bit size: %d\n", _BITSET_BITS_PER_CHUNK)
    35  	fmt.Printf("\tChunk len:      %d\n", len(bs.bs))
    36  	fmt.Printf("\tChunk capacity: %d\n", cap(bs.bs))
    37  	fmt.Printf("\tCapacity:       %d\n", bs.Capacity())
    38  	fmt.Printf("\tIs empty:       %t\n", bs.IsEmpty())
    39  	fmt.Printf("\tCount ones:     %d\n", countOnes)
    40  	fmt.Printf("\tAs chunks:      %v\n", bs.bs)
    41  
    42  	var bits strings.Builder
    43  	bits.Grow(int(bs.chunkSize() * (_BITSET_BITS_PER_CHUNK + 1)))
    44  	for _, chunk := range bs.bs {
    45  		_, _ = fmt.Fprintf(&bits, "%b ", chunk)
    46  	}
    47  
    48  	fmt.Printf("\tAs bits:        [%s]\n", strings.TrimSpace(bits.String()))
    49  	fmt.Printf("\tAs elems:       %v\n", bs.DebugOnesAsSlice(countOnes))
    50  }