bmap

Check-in Differences
Login

Check-in Differences

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Difference From bmap-0.2.0 To bmap-0.2.1

2024-03-21
13:35
Add unsafe set_unchecked(). check-in: d8806abadd user: jan tags: trunk
10:39
Release maintenance. check-in: d43e21d672 user: jan tags: bmap-0.2.1, trunk
10:37
Implement Debug for CountedBitmap. check-in: 39fed45718 user: jan tags: trunk
09:02
Update changelog. check-in: 93c247c785 user: jan tags: trunk
08:57
Happy clippy. check-in: e5ebec2954 user: jan tags: bmap-0.2.0, trunk
08:54
Merge. check-in: ae8ad4dec1 user: jan tags: trunk

Changes to Cargo.toml.

1
2
3
4
5
6
7
8
9
10
[package]
name = "bmap"
version = "0.2.0"
edition = "2021"
license = "0BSD"
# https://crates.io/category_slugs
categories = [ "data-structures" ]
keywords = [ "bitmap", "bitvec" ]
repository = "https://repos.qrnch.tech/pub/bmap"
description = "A bitmap with an internal counter."


|







1
2
3
4
5
6
7
8
9
10
[package]
name = "bmap"
version = "0.2.1"
edition = "2021"
license = "0BSD"
# https://crates.io/category_slugs
categories = [ "data-structures" ]
keywords = [ "bitmap", "bitvec" ]
repository = "https://repos.qrnch.tech/pub/bmap"
description = "A bitmap with an internal counter."

Changes to src/lib.rs.

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
//! Container of bits adressable by an index.



pub mod err;

pub use err::Error;

/// Number of bits per slot in the bits vector.
const NUM_WORD_BITS: usize = std::mem::size_of::<usize>() * 8;


/// A compact list of bits.
pub struct CountedBitmap {
  bits: Vec<usize>,

  /// Number of bits in bit map.
  length: usize,

  /// Number of remaining bits.  This is functionally equivalent to "total
  /// number of zeroes in the container".
  remain: usize
}























impl CountedBitmap {
  /// Create a new bit vector which can hold `bitcount` number of bits.
  ///
  /// All bits will be initialized to `0`.
  pub fn new(bitcount: usize) -> Self {


>
>



















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
//! Container of bits adressable by an index.

use std::fmt;

pub mod err;

pub use err::Error;

/// Number of bits per slot in the bits vector.
const NUM_WORD_BITS: usize = std::mem::size_of::<usize>() * 8;


/// A compact list of bits.
pub struct CountedBitmap {
  bits: Vec<usize>,

  /// Number of bits in bit map.
  length: usize,

  /// Number of remaining bits.  This is functionally equivalent to "total
  /// number of zeroes in the container".
  remain: usize
}

impl fmt::Debug for CountedBitmap {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    let blocks: Vec<String> = self
      .iter_ones_block()
      .map(|(first, last)| {
        if first != last {
          format!("{}-{}", first, last)
        } else {
          format!("{}", first)
        }
      })
      .collect();
    let set_blocks = blocks.join(",");
    write!(
      f,
      "BMap {{ length: {}, remain: {}, [{}] }}",
      self.length, self.remain, set_blocks
    )
  }
}


impl CountedBitmap {
  /// Create a new bit vector which can hold `bitcount` number of bits.
  ///
  /// All bits will be initialized to `0`.
  pub fn new(bitcount: usize) -> Self {
548
549
550
551
552
553
554
555





556
































557
    assert!(bmap.is_finished());

    let mut bmap = CountedBitmap::new(1);
    assert!(!bmap.is_finished());
    bmap.set(0).unwrap();
    assert!(bmap.is_finished());
  }
}






































// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :







|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
    assert!(bmap.is_finished());

    let mut bmap = CountedBitmap::new(1);
    assert!(!bmap.is_finished());
    bmap.set(0).unwrap();
    assert!(bmap.is_finished());
  }

  #[test]
  fn dbg_output0() {
    let bmap = CountedBitmap::new(3);
    let s = format!("{:?}", bmap);
    assert_eq!(s, "BMap { length: 3, remain: 3, [] }");
  }

  #[test]
  fn dbg_output1() {
    let mut bmap = CountedBitmap::new(3);
    bmap.set(1).unwrap();
    let s = format!("{:?}", bmap);
    assert_eq!(s, "BMap { length: 3, remain: 2, [1] }");
  }

  #[test]
  fn dbg_output2() {
    let mut bmap = CountedBitmap::new(5);
    bmap.set(1).unwrap();
    bmap.set(2).unwrap();
    let s = format!("{:?}", bmap);
    assert_eq!(s, "BMap { length: 5, remain: 3, [1-2] }");
  }

  #[test]
  fn dbg_output3() {
    let mut bmap = CountedBitmap::new(7);
    bmap.set(1).unwrap();
    bmap.set(2).unwrap();

    bmap.set(4).unwrap();
    bmap.set(5).unwrap();

    let s = format!("{:?}", bmap);
    assert_eq!(s, "BMap { length: 7, remain: 3, [1-2,4-5] }");
  }
}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :

Changes to www/changelog.md.

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
# Change Log

⚠️  indicates a breaking change.

## [Unreleased]

[Details](/vdiff?from=bmap-0.1.0&to=trunk)























### Added

- `CountedBitmap::is_empty()` returns `true` is no bits have been set in the
  bit map. 

### Changed

- ⚠️ `CountedBitmap::new()` made infallible.

### Removed

---

## [0.1.0]

Initial release.







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|





<
<






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
# Change Log

⚠️  indicates a breaking change.

## [Unreleased]

[Details](/vdiff?from=bmap-0.2.1&to=trunk)

### Added

### Changed

### Removed

---

## [0.2.1] - 2024-03-21

[Details](/vdiff?from=bmap-0.2.0&to=bmap-0.2.1)

### Changed

- Implement `Debug` for `CountedBitmap`.

---

## [0.2.0] - 2024-03-21

[Details](/vdiff?from=bmap-0.1.0&to=bmap-0.2.0)

### Added

- `CountedBitmap::is_empty()` returns `true` is no bits have been set in the
  bit map.

### Changed

- ⚠️ `CountedBitmap::new()` made infallible.



---

## [0.1.0]

Initial release.