Skip to content

Conversation

@m-a-king
Copy link

Summary

Refactor the node-bits calculation in TsidFactory.Builder.getNodeBits() by replacing a floating-point logarithm expression with an equivalent integer bit operation.
This change improves clarity and mathematical robustness, and avoids unnecessary floating-point operations in a code path that runs only during factory initialization.

Why a Refactor?

Although the bit-operation approach is theoretically faster, this logic runs only once during startup, so the main motivation is not performance.

Instead, the change aims to:

  • remove floating-point precision concerns,
  • express the intent (compute required bit width) more directly, and
  • align with the library’s existing bit-oriented style.

Testing

The existing testWithNodeCount() test already covers all valid nodeBits cases (0–20), and the new implementation produces identical results, ensuring full backward compatibility.


Thank you for maintaining this excellent library!
Happy to revise anything if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant