algebra icon indicating copy to clipboard operation
algebra copied to clipboard

Unify `BitIteratorBE` and `BitIteratorLE` with an `Endian` enum

Open tcoratger opened this issue 1 year ago • 0 comments

Description

Currently, there are two separate implementations for iterating over a slice of u64 in big-endian and little-endian order, namely BitIteratorBE and BitIteratorLE. These implementations have similar functionalities but are implemented separately. This proposal suggests unifying them into a single implementation with an Endian enum to denote whether the iteration should be in big-endian or little-endian order.

Proposed Changes

  1. Introduce an Endian enum with variants big and little.
  2. Modify the iterator implementations to handle both big-endian and little-endian orders based on the value of the Endian enum.

Example Usage

use Endian::*;

// Usage example with the Endian enum
let mut iter = BitIterator::new(&data, Endian::big); // Big-endian order
let mut iter = BitIterator::new(&data, Endian::little); // Little-endian order

Benefits

  • Simplifies the codebase by removing duplicate implementations.
  • Provides a more consistent and unified interface.
  • Allows for easy specification of the endianness using the Endian enum.

tcoratger avatar Feb 20 '24 17:02 tcoratger