-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add an hasSize
function
#7
Conversation
src/root.zig
Outdated
@@ -210,6 +210,15 @@ pub fn AlgorithmType( | |||
self.max_needle = max_needle; | |||
} | |||
|
|||
// Check is there is enough memory allocated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Check is there is enough memory allocated | |
// Check if buffers have sufficient memory for a given haystack and | |
// needle length. |
src/root.zig
Outdated
if (self.max_haystack < max_haystack or self.max_needle < max_needle) { | ||
return false; | ||
} else { | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (self.max_haystack < max_haystack or self.max_needle < max_needle) { | |
return false; | |
} else { | |
return true; | |
} | |
return (max_haystack <= self.max_haystack) and (max_needle <= self.max_needle); |
It's easier just to check the positive case.
src/root.zig
Outdated
@@ -210,6 +210,15 @@ pub fn AlgorithmType( | |||
self.max_needle = max_needle; | |||
} | |||
|
|||
// Check is there is enough memory allocated | |||
pub fn hasSize(self: *Self, max_haystack: usize, max_needle: usize) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn hasSize(self: *Self, max_haystack: usize, max_needle: usize) bool { | |
pub fn hasSize(self: *const Self, max_haystack: usize, max_needle: usize) bool { |
This won't and should not mutate memory, so we mark the pointer as const
.
src/root.zig
Outdated
// Check is there is enough memory allocated | ||
pub fn hasSize(self: *Ascii, max_haystack: usize, max_needle: usize) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Check is there is enough memory allocated | |
pub fn hasSize(self: *Ascii, max_haystack: usize, max_needle: usize) bool { | |
// Check if buffers have sufficient memory for a given haystack and | |
// needle length. | |
pub fn hasSize(self: *const Ascii, max_haystack: usize, max_needle: usize) bool { |
src/unicode.zig
Outdated
// Check is there is enough memory allocated | ||
pub fn hasSize(self: *Unicode, max_haystack: usize, max_needle: usize) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Check is there is enough memory allocated | |
pub fn hasSize(self: *Unicode, max_haystack: usize, max_needle: usize) bool { | |
// Check if buffers have sufficient memory for a given haystack and | |
// needle length. | |
pub fn hasSize(self: *const Unicode, max_haystack: usize, max_needle: usize) bool { |
In your previous PR you had some tests that made sure |
But just a question : is it an error that there is Line 256 in 2c5d606
It makes score fail when there is just the size needed.
|
Yes that is a mistake. Well spotted! Make sure there's a test that catches it and then I think this will be ready to merge. Edit: I see you're ahead of me and already have! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all great! My only suggestion is to add a handful more tests that check that smaller sizes pass, and that larger sizes do indeed fail (even after resize).
When you're happy, let me know and we can merge.
Co-authored-by: Fergus Baker <[email protected]>
For me, all is good. We can merge it. |
No description provided.