Skip to content

Conversation

@ia7ck
Copy link
Owner

@ia7ck ia7ck commented Nov 12, 2025

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the RollingHash implementation to support custom base values through const generics, and replaces the is_substring method with more flexible substring and position methods.

  • Converts RollingHash to a generic struct with a const BASE parameter, allowing different hash bases
  • Introduces a Substring type to represent extracted substrings with their hash values
  • Replaces the boolean is_substring method with position that returns the index of the first occurrence

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let mut pows = vec![1; n + 1];
for (i, &x) in xs.iter().enumerate() {
// hashes[i + 1] = hashes[i] * BASE + x
// hashes[i + 1] = hashes[i] * base + x
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment uses lowercase "base" but the actual constant is uppercase "BASE". Consider updating the comment to match: "hashes[i + 1] = hashes[i] * BASE + x" for consistency with the code.

Suggested change
// hashes[i + 1] = hashes[i] * base + x
// hashes[i + 1] = hashes[i] * BASE + x

Copilot uses AI. Check for mistakes.
Comment on lines +65 to +69
pub fn substring(&self, range: ops::Range<usize>) -> Substring<BASE> {
let len = range.end - range.start;
let hash = self.hash(range);
Substring::new(hash, len)
}
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substring method lacks documentation. Consider adding a doc comment explaining what this method does, its parameters, and what it returns. For example: /// Creates a Substring from the specified range of this RollingHash.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +76
pub fn position(&self, sub: &Substring<BASE>) -> Option<usize> {
if sub.len > self.len() {
return None;
}
false
(0..=self.len() - sub.len).find(|&i| self.hash(i..(i + sub.len)) == sub.hash)
}
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position method lacks documentation. Consider adding a doc comment explaining what this method does, its parameters, return value (e.g., returns the first position where the substring is found, or None if not found), and complexity. For example: /// Finds the first position of the substring in this RollingHash. Returns None if not found. O(n) where n is the length of this RollingHash.

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +83
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Substring<const BASE: u64> {
hash: u64,
len: usize,
}
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Substring struct lacks documentation. Consider adding a doc comment explaining what this struct represents and its purpose. For example: /// Represents a substring with its precomputed hash value and length.

Copilot uses AI. Check for mistakes.
pub fn is_empty(&self) -> bool {
self.xs.is_empty()
}

Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base method lacks documentation. Consider adding a doc comment explaining what this method returns. For example: /// Returns the base value used for this rolling hash.

Suggested change
/// Returns the base value used for this rolling hash.

Copilot uses AI. Check for mistakes.
// hashes[i + 1] = hashes[i] * base + x
hashes[i + 1] = calc_mod(mul(hashes[i], BASE) + x);
// pows[i + 1] = pows[i] * BASE
// pows[i + 1] = pows[i] * base
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment uses lowercase "base" but the actual constant is uppercase "BASE". Consider updating the comment to match: "pows[i + 1] = pows[i] * BASE" for consistency with the code.

Copilot uses AI. Check for mistakes.
@ia7ck ia7ck enabled auto-merge November 15, 2025 11:29
@ia7ck ia7ck merged commit 21aa3ca into master Nov 15, 2025
6 checks passed
@ia7ck ia7ck deleted the rolling-hash branch November 15, 2025 11:30
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.

2 participants