Skip to content

Commit

Permalink
[README] Count<Layout> and BitCountable.
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Jul 8, 2024
1 parent ad35751 commit d25f215
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [Upsize binary integer elements with DataInt\<U8\>](#corekit-upsize)
- [Lightweight text decoding and encoding with TextInt](#corekit-text-int)
- [Type-safe bit casts with BitCastable\<BitPattern\>](#corekit-bit-cast)
- [Bit counting with Count\<Layout\> and BitCountable](#corekit-bit-count)
- [Generic logic gates with BitOperable](#corekit-bitwise-logic)
- [More ones and zeros with Bit, Sign and Signum](#corekit-bit-sign-signum)
* [DoubleIntKit](#doubleintkit)
Expand Down Expand Up @@ -394,6 +395,25 @@ via the init(raw:) bulk operation. Note that such type relationships are generic
to all binary integers. Also, note that this method is both fully generic and fully recoverable.
The init(load:) method is similar, but it returns the bit pattern that fits.

<a name="corekit-bit-count"/>

#### Bit counting with Count\<Layout\> and BitCountable

> Please roll a **D20** arcana check.
An arbitrary binary integer's bit pattern extends infinitely, yet its bit pattern has an end.
Count\<IX\> is a pointer-bit model that can count the bits of any binary integer stored in memory.
It does this by reinterpreting the last bit as logarithmically infinite.

```
min ..< msb: [0,  IX.max + 0]
msb ... max: [∞ - IX.max,  ∞] ≤ log2(UXL.max + 1)
```

All binary integer types and all data integer types let you perform bit-counting operations;
the BitCountable protocol unifies them. Their common protocol requires methods like *size()*
and *ascending(\_:)* then derives methods like *entropy()* and *nonascending(\_:)* for them.

<a name="corekit-bitwise-logic"/>

#### Generic logic gates with BitOperable
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreKit/BitCountable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public protocol BitCountable {
///
/// - Invariant: `count(x) + noncount(x) == size()`
///
@inlinable func size() -> Count<IX>
@inlinable borrowing func size() -> Count<IX>

/// The `bit` count in `self`.
///
Expand Down

0 comments on commit d25f215

Please sign in to comment.