-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39e789e
commit 41e0917
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class PodHelper | ||
function insert(arr, start, el) | ||
res = [] | ||
for i = 0 to arr.count() - 1 step 1: | ||
if i = start then res.push(el) | ||
res.push(arr[i]) | ||
end for | ||
return res | ||
end function | ||
|
||
function binaryInsert(arr, el) | ||
res = [] | ||
idx = m.getSortedIndex(arr, el, 0, arr.count() - 1) | ||
if idx >= 0 | ||
res = m.insert(arr, idx, el) | ||
else if idx < 0 | ||
res = m.insert(arr, idx * -1 - 1, el) | ||
end if | ||
return res | ||
end function | ||
|
||
private function getSortedIndex(arr, el, lBound, uBound) | ||
m = lBound | ||
n = uBound | ||
while m <= n | ||
k = (n + m) >> 1 | ||
cmp = el.renderTime - arr[k].renderTime | ||
if cmp > 0 | ||
m = k + 1 | ||
else if cmp < 0 | ||
n = k - 1 | ||
else return k | ||
end if | ||
end while | ||
return -m - 1 | ||
end function | ||
end class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters