diff --git a/src/observable/list/SortedMapList.js b/src/observable/list/SortedMapList.js index 7f525fff..a3479be0 100644 --- a/src/observable/list/SortedMapList.js +++ b/src/observable/list/SortedMapList.js @@ -1,5 +1,5 @@ import BaseObservableList from "./BaseObservableList.js"; - +import sortedIndex from "../../utils/sortedIndex"; /* @@ -25,35 +25,6 @@ so key -> Map -> value -> node -> *parentNode -> rootNode with a node containing {value, leftCount, rightCount, leftNode, rightNode, parentNode} */ - -/** - * @license - * Based off baseSortedIndex function in Lodash - * Copyright JS Foundation and other contributors - * Released under MIT license - * Based on Underscore.js 1.8.3 - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - */ -function sortedIndex(array, value, comparator) { - let low = 0; - let high = array.length; - - while (low < high) { - let mid = (low + high) >>> 1; - let cmpResult = comparator(value, array[mid]); - - if (cmpResult > 0) { - low = mid + 1; - } else if (cmpResult < 0) { - high = mid; - } else { - low = high = mid; - } - } - return high; -} - - // does not assume whether or not the values are reference // types modified outside of the collection (and affecting sort order) or not diff --git a/src/utils/sortedIndex.js b/src/utils/sortedIndex.js new file mode 100644 index 00000000..70eaa9b8 --- /dev/null +++ b/src/utils/sortedIndex.js @@ -0,0 +1,26 @@ +/** + * @license + * Based off baseSortedIndex function in Lodash + * Copyright JS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ +export default function sortedIndex(array, value, comparator) { + let low = 0; + let high = array.length; + + while (low < high) { + let mid = (low + high) >>> 1; + let cmpResult = comparator(value, array[mid]); + + if (cmpResult > 0) { + low = mid + 1; + } else if (cmpResult < 0) { + high = mid; + } else { + low = high = mid; + } + } + return high; +}