Skip to content

Instantly share code, notes, and snippets.

@tpmccallum
Last active November 22, 2020 03:00
Show Gist options
  • Save tpmccallum/71ae0d99d84e2d63b44b8813fdab899a to your computer and use it in GitHub Desktop.
Save tpmccallum/71ae0d99d84e2d63b44b8813fdab899a to your computer and use it in GitHub Desktop.
MaxGraey_search_bytes_solution_II
function isSubset(haystack, needle) {
return new Promise(function(resolve, reject) {
let n = needle.length,
m = haystack.length,
d = m - n;
outer: for (let i = 0; i <= d; ++i) {
for (let j = 0; j < n; ++j) {
if (needle[j] !== haystack[i + j]) {
continue outer
}
}
resolve("Present");
}
resolve("Absent")
});
}
var buffer_1 = new ArrayBuffer(14500);
var buffer_2 = new ArrayBuffer(1000000);
var needle = new Uint8Array(buffer_1);
var haystack = new Uint8Array(buffer_2);
needle.fill(111);
haystack.fill(111);
if (needle_length < 1 || needle_length > haystack_length) {
alert("Needle length must be greater than zero and less than haystack length");
} else {
isSubset(haystack, needle)
.then(function(result) {
console.log("Result: " + result);
})
.catch(function() {
console.log("Error");
});
}
@tpmccallum
Copy link
Author

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