-
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
Changes from 1 commit
4be4e25
a4587b9
e70e541
368af07
af63859
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This won't and should not mutate memory, so we mark the pointer as |
||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It's easier just to check the positive case. |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// Compute matching score | ||||||||||||||
pub fn score( | ||||||||||||||
self: *Self, | ||||||||||||||
|
@@ -649,6 +658,11 @@ pub const Ascii = struct { | |||||||||||||
pub fn resize(self: *Ascii, max_haystack: usize, max_needle: usize) !void { | ||||||||||||||
try self.alg.resize(max_haystack, max_needle); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
return self.alg.hasSize(max_haystack, max_needle); | ||||||||||||||
} | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
fn doTestScore(alg: *Ascii, haystack: []const u8, needle: []const u8, comptime score: i32) !void { | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -219,6 +219,11 @@ pub const Unicode = struct { | |||||||||||
pub fn resize(self: *Unicode, max_haystack: usize, max_needle: usize) !void { | ||||||||||||
try self.alg.resize(max_haystack, max_needle); | ||||||||||||
} | ||||||||||||
|
||||||||||||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
return self.alg.hasSize(max_haystack, max_needle); | ||||||||||||
} | ||||||||||||
}; | ||||||||||||
|
||||||||||||
fn doTestScoreUnicode( | ||||||||||||
|
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.