-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbitmap_windows.go
83 lines (72 loc) · 1.76 KB
/
bitmap_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package hwloc
//#cgo LDFLAGS: -lhwloc
//#cgo LDFLAGS: -static -static-libgcc
// #include <hwloc.h>
// #include <hwloc/bitmap.h>
import "C"
import "unsafe"
// BitMap is a struct containing a slice of bytes,
// being used as a bitmap.
type BitMap struct {
bm C.hwloc_bitmap_t
}
// NewBitmap returns a BitMap. It requires a size. A bitmap with a size of
// eight or less will be one byte in size, and so on.
func NewBitmap(set C.hwloc_bitmap_t) BitMap {
b := BitMap{
bm: set,
}
if set == nil {
b.bm = C.hwloc_bitmap_alloc()
}
return b
}
// Destroy free the BitMap
func (b BitMap) Destroy() {
if b.bm != nil {
C.hwloc_bitmap_free(b.bm)
}
}
// Set sets a position in
// the bitmap to 1.
func (b BitMap) Set(i uint64) error {
C.hwloc_bitmap_set(b.bm, C.uint(i))
return nil
}
// Unset sets a position in
// the bitmap to 0.
func (b BitMap) Unset(i uint64) error {
C.hwloc_bitmap_clr(b.bm, C.uint(i))
return nil
}
// Values returns a slice of ints
// represented by the values in the bitmap.
func (b BitMap) Values() ([]uint64, error) {
list := make([]uint64, 0)
return list, nil
}
// IsSet returns a boolean indicating whether the bit is set for the position in question.
func (b BitMap) IsSet(i uint64) (bool, error) {
if C.hwloc_bitmap_isset(b.bm, C.uint(i)) == 1 {
return true, nil
}
return false, nil
}
// IsZero Test whether bitmap is empty
// return 1 if bitmap is empty, 0 otherwise.
func (b BitMap) IsZero() (bool, error) {
if C.hwloc_bitmap_iszero(b.bm) == 1 {
return true, nil
}
return false, nil
}
func (b BitMap) String() string {
var bitmap = C.CString("")
defer C.free(unsafe.Pointer(bitmap))
C.hwloc_bitmap_asprintf(&bitmap, b.bm)
var res = C.GoString(bitmap)
return res
}
func FromString(input string) (BitMap, error) {
return NewBitmap(nil), nil
}