Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@algorithm.ts/lower-bound

guanghechen30MIT2.0.14TypeScript support: included

Find the index of first elements which greater or equals than the target element.

algorithm, lower bound

readme

@algorithm.ts/lower-bound


A typescript implementation of the lower bound algorithm.

The lower bound algorithm is desired to find the index of first elements which greater or equals than the target element.

Install

  • npm

    npm install --save @algorithm.ts/lower-bound
  • yarn

    yarn add @algorithm.ts/lower-bound
  • deno

    import lowerBound from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/lower-bound/src/index.ts'

Usage

  • Basic

    import lowerBound from '@algorithm.ts/lower-bound'
    
    // elements should be ordered.
    const elements: number[] = [2, 3, 7, 11, 19]
    
    // Find the index of elements which is the first element greater or equal than 8
    // elements[3] = 11 >= 8
    lowerBound(0, elements.length, x => elements[x] - 8) // => 3
    
    // Find the index of elements which is the first element greater or equal than 3
    // elements[1] = 3 >= 3
    lowerBound(0, elements.length, x => elements[x] - 3) // => 1
  • Complex

    import lowerBound from '@algorithm.ts/lower-bound'
    
    const fruits = [
      { type: 'orange', price: 3 },
      { type: 'apple', price: 10 },
      { type: 'banana', price: 10 },
      { type: 'watermelon', price: 12 },
      { type: 'lemon', price: 15 },
    ]
    
    // Find the index of fruits which price is greater or equal than 10
    lowerBound(0, fruits.length, x => fruits[x].price - 10) // => 1
    
    // Find the index of fruits which price is greater or equal than 11
    lowerBound(0, fruits.length, x => fruits[x].price - 11) // => 3
  • Bigint

    import { lowerBoundBigint } from '@algorithm.ts/lower-bound'
    
    lowerBoundBigint(-500000000000n, 5000000000n, x => x - 1n) // => 1n

changelog

Changelog

2.0.13 (2022-06-26)

Changed

  • 🔧 chore: fix test coverage fails [cb09bca]
  • ⬆️ chore: ugprade devDependencies [b86a374]
  • 🎨 refactor(gomoku): refactor algorithm [339864e]

Miscellaneous

  • 📝 docs: update CHANGELOG [f5618c6]

2.0.12 (2022-06-07)

Added

Changed

  • 🔧 chore: tweak coverageThreshold [1caa894]
  • ⬆️ chore: upgrade devDependencies [63be840]
  • ⚡ improve: optimize gomoku [2c839a4]
  • 🎨 improve(dijkstra): refactor codes [9f2f4e3]
  • 🚚 move: migrate getShortestPath from @algorithm.ts/bellman-ford to @algorithm.ts/graph [682672a]

Miscellaneous

  • 📝 docs: update CHANGELOG [c79f084]

2.0.11 (2022-04-19)

Added

  • ✅ test(bellman-ford): update tests [bfd07c6]
  • ✨ feat(graph): implement @algorithm.ts/graph [eafa1e9]

Changed

  • 🎨 improve(bellman-ford): use @algorithm.ts/graph to simplify codes [fe5e069]
  • 🎨 refactor(#1): refactor bellman-ford & update tests [a1e6268]
  • 🎨 refactor(#1): refactor bellman-ford to support obtaining a specific shortest path [ad78413]

Miscellaneous

  • Merge pull request #2 from guanghechen/develop [aeb83d1]
  • 📝 docs(#1): update README and tests [eee875c]
  • 📝 docs: update CHANGELOG [24da53e]

2.0.10 (2022-04-12)

Changed

  • ⚡ improve(gomoku): optimize unnecessary operations on maintaining candidates [db9374f]
  • ⚡ improve(gomoku): maintain candidates in priority-queue cross state changes [595490b]

Miscellaneous

  • 📝 docs: update CHANGELOG [8d3876a]

2.0.9 (2022-04-10)

Added

  • ✅ test(gomoku): update tests [062fa3d]

Changed

  • 🎨 improve(gomoku): tweak constants [8ffd74a]
  • 🔧 chore: upgrade dependencies [c4d720c]
  • 🚨 style: fix lint warnings [e478cc1]

Fixed

  • 🐛 fix(gomoku): fix unreasonable scoreMap [475cc20]

Miscellaneous

  • 📝 docs: update CHANGELOG [8fbba14]

2.0.8 (2022-04-10)

Added

  • ✅ test(gomoku): update tests [aa2c739]
  • ✅ test(gomoku): update tests [963bea8]
  • ✨ feat(priority-queue): support new method 'replaceTop' [cf9bede]
  • ✨ feat(priority-queue): support new method `splice` [1bf5b7b]
  • ✨ feat: support enqueues multiple elements [f5f8d23]

Changed

  • 🎨 refactor(gomoku): refactor code -- separate minimax-searcher for different layers [4ba6af6]
  • ⚡ improve(gomoku): improve performance [2bcb90a]
  • 🎨 refactor(gomoku): refactor codes [3d8fa39]

Removed

  • 🔥 improve(gomoku): remove unused codes [7dadeca]

Miscellaneous

  • 📝 docs(priority-queue): update README [67a0eeb]
  • 📝 docs: update CHANGELOG [0c575e5]

2.0.8-alpha.0 (2022-04-05)

Changed

  • ⚡ improve(gomoku): maintain mustDropPos to get the top priority candidate faster [86113e8]
  • ⚡ improve(gomoku): improve: detect must-drop position [3bfbb9e]
  • ⚡ improve(gomoku): tweak search thresholds [2f03fe1]
  • ⚡ improve(gomoku): use topCandidate in searchDeepSpace [11abb27]
  • ⚡ improve(gomoku): use priority_queue to improve GomokuState.expand [a360ccf]
  • 🎨 refactor(gomoku): rename type fields [8a6adad]
  • ⚡ improve(gomoku): tweak search thresholds [a266744]
  • ⚡ improve(gomoku): hierarchical search [9db8961]

Miscellaneous

  • 📝 docs: update CHANGFELOG [75c5103]

2.0.7 (2022-04-03)

Changed

  • ⚡ improve: improve with priority-queue [8cfe922]
  • ⚡ improve(gomoku): tweak scoreMap [af85d27]

Removed

  • 🔥 improve: remove unused codes [36ce18f]

Miscellaneous

  • improve: add POSSIBILITY_SEARCH_EQUIV_CANDIDATE [88ea7ec]
  • improve: tweak algorithm [fd90575]
  • 📝 docs: update CHANGELOG [f4b1e6d]

2.0.7-alpha.1 (2022-04-03)

Changed

  • 🎨 improve(gomoku): add GomokuCountMap [9e326dd]
  • ⚡ improve(gomoku): cache candidate score per position and direction [41bbb77]
  • 🎨 improve(gomoku): refactor codes [0099728]
  • 🎨 improve(gomoku): refactor codes [93f2517]
  • 🎨 refactor(gomoku): refactor algorithm [e79b67f]
  • 🎨 feat(priority-queue): support to specify the startIndex and endIndex of the initial elements [e83506f]

Fixed

  • 🐛 fix: tweak initial constants [a69f372]

Miscellaneous

  • Merge branch 'develop-gomoku' [4105827]
  • 📝 docs: update CHANGELOG [634026a]

2.0.7-alpha.0 (2022-03-27)

Added

  • ✅ test(gomoku): update tests [a967c8b]
  • ✅ test(gomoku): update snapshots [2dfd446]

Changed

  • ⚡ improve(gomoku): revert state cache [54c7363]
  • 🎨 improve(gomoku): default search neighbors within 2-steps as candidates [8a9512e]
  • ⚡ improve(gomoku): tweak score map [52c48b1]
  • ⚡ improve(gomoku): tweak score map [2dae96c]
  • ⚡ improve: only re-calc related candidate scores [f7d3b43]
  • 🎨 refactor(gomoku): refactor score func [c8976b3]
  • 🎨 refactor: move placedCount from GomokuState to GomokuContext [69f7648]
  • 🎨 refactor: move board from GomokuState to GomokuContext [40810bb]

Removed

  • 🔥 improve: remove dead codes [1f3772f]
  • 🔥 improve: remove unused vars [670d209]

Fixed

  • 🐛 fix: fix incorrectly result in '_reAppriseCandidates' [0e7e820]
  • 🐛 fix: add the center pos as initial candidate [496ceb5]
  • 🐛 fix(gomoku): avoid to parse a invalid pos id [c19a328]

Miscellaneous

  • 📝 docs: update CHANGELOG [ad52739]

2.0.6 (2022-03-26)

Changed

  • ⚡ improve(gomoku): tweak score map [49f13d4]
  • ⚡ improve(gomoku): avoid unnecessary check [278d041]
  • ⚡ improve(gomoku): avoid encode/decode coordinates [56fa8cf]
  • ⚡ improve(gomoku): avoid encode/decode coordinates [cf0926e]
  • ⚡ improve(gomoku): use 'context.safeMove()' and 'context.fastMove()' instead of 'context.move()' [616f8a6]
  • 🎨 refactor: rename NEXT_MOVER_BUFFER_FAC to NEXT_MOVER_MAX_BUFFER [ed0de20]
  • ⚡ improve(gomoku): avoid division and modulo operations [754b580]

Miscellaneous

  • 📝 docs: update CHANGELOG [c68789c]

2.0.5 (2022-03-23)

Added

  • ✅ test(gomoku): udpate tests [1bfebee]
  • ✅ test: update tests [5d6b494]

Changed

  • 🔧 chore: update jest coverageThreshold [0ecd53d]
  • ⬆️ chore: upgrade devDependencies [cb69cec]
  • 🔧 chore: update jest coverageThreshold [0e22cd3]
  • 🎨 improve(gomoku): refactor updateRelatedConShapeCountMap to make it more readable [45c6128]
  • 🎨 improve(gomoku): detected max-possible size for gap shapes [697b131]
  • 🎨 improve: prefer iterator instead of high-level func [8270395]

Miscellaneous

  • 📝 docs: update CHANGELOG [fe32d92]

2.0.4 (2022-03-20)

Added

  • ✨ feat(gomoku): add GomokuStateCompressor [ad419ad]
  • ✅ test(gomoku): update tests [40ed757]
  • ✅ test: update tests [d78bfdb]
  • ✨ feat: implement @algorithm.ts/gomoku [a961f2c]

Changed

  • 🔧 chore: update coverageThreshold [26f92fc]
  • 🎨 improve: detect max-possible size [ddbc92b]
  • ⚡ improve(gomoku): next mover should take a advantage factor [af99efd]
  • 🎨 refactor(gomoku): refactor interface of alphaBeta [f88940d]
  • ⚡ improve(gomoku): cache intermediate search states to improve performance [b82504a]
  • 🎨 improve(gomoku): detect COMPRESS_MOVE_BIT_BASE automaticly [1752cca]
  • 🎨 improve: update randomMove to perform a reasonable move & update tests [116b563]
  • 🎨 improve(gomoku): refactor codes [40569ae]
  • ⚡ improve(gomoku): improve algorithm [c31b64b]
  • ⚡ improve(gomoku): tweak scoreMap [a5ced54]

Removed

  • 🔥 improve(gomoku): remove dead codes [d5d779e]

Fixed

  • 🐛 fix(gomoku): fix logic error in score func [2c9fde2]
  • 🐛 fix(gomoku): tweak score [e9229ad]
  • 🐛 fix(gomoku): tweak score [7befcaa]
  • 🐛 fix(gomoku): init continuouslyShapeCountMap when GomokuCountMap.init is called [6dfa81e]
  • 🐛 fix(gomoku): fix logic error [8e9ac56]

Miscellaneous

  • Merge branch 'develop-gomoku' [43896da]
  • feat(gomoku): maintain gapShapeCountMap [6b60cde]
  • fix(gomoku): fix logic error [e1aa811]
  • 📝 docs: update CHANGELOG [7d49547]

2.0.3 (2022-02-24)

Fixed

  • 🐛 fix: revert findMinLexicographicalLCS as the previous change is incorrectly [57485d6]

Miscellaneous

  • 📝 docs: update CHANGELOG [afd8033]

2.0.2 (2022-02-24)

Changed

  • 🎨 [BREAKING] feat: change return type of findMinLexicographicalLCS -- return pairs instead of confusing number[] [b0af7fe]
  • ⚡ improve: optimize space complexity, from O(N1xN2) to O(N1) or O(N2) [f3efd52]

Miscellaneous

  • 📝 docs: update README [79e9ac6]
  • 📝 docs: update CHANGELOG [58e20ce]

2.0.1 (2022-02-22)

Added

  • ✨ feat: implement '@algorithm.ts/lcs' [3c59c78]

Miscellaneous

  • 📝 docs: update package descriptions [a2455ed]
  • 📝 docs: update README [de7b296]
  • 📝 docs: update CHANGELOG [d3d48ab]

2.0.0 (2022-02-06)

Added

  • ✅ test: update tests [44297c8]
  • ✅ test: update tests [949a6c7]
  • ✅ test(mcmf): update tests [7c3e3dc]
  • ✅ test: simplify tests [75d9be3]
  • ✅ test(isap): update tests [f3f9841]
  • ✅ test(dinic): update tests [4bc8373]
  • ✨ feat: implement '@algorithm.ts/bipartite-graph-matching' [5a46561]
  • ✅ test: update tests [e942a21]

Changed

  • 🔧 chore: update coverage threshold (make strictly) [ac18ca0]
  • 🎨 [BREAKING] feat: rewrite '@algorithm.ts/sliding-window' [5521403]

Miscellaneous

  • 📝 docs: update CHANGELOG [5ffc752]

2.0.0-alpha.0 (2022-02-02)

Added

  • ✨ feat: implement '@algorithm.ts/bellman-ford' [ca399d0]
  • ✨ feat: implement '@algorithm.ts/dijkstra-bigint' [5b3cf4f]
  • ✅ test: update tests & update README [e8882e1]

Changed

  • 🎨 [BREAKING] refactor: add 'I' as prefix name for interface types [7253441]
  • 🎨 [BREAKING] improve: change the interface of @algorithm.ts/dijkstra and @algorithm.ts/dijkstra-bigint [6854588]
  • 🎨 improve(mcmf): update types & improve shortest-path algorithm [4fbcbdc]
  • 🎨 refactor: rename 'PriorityQueue' to 'IPriorityQueue' [0004fe8]
  • 🎨 refactor: rename 'CircularQueue' to 'ICircularQueue' [ae8f349]

Breaking changes

  • 💥 [breaking] refactor: refactor dijkstra to make it more robust [1543fea]

Miscellaneous

  • 📝 docs: update READMEs [4341cb8]
  • 📝 docs: update README [f3f0807]

1.0.24 (2022-01-22)

Added

  • ✨ feat:implement '@algorithm.ts/huffman' [c3ebdda]
  • ✨ feat:implement '@algorithm.ts/base64' [5aef00b]

Changed

  • 🔧 chore: update jest coveraage threshold [07fa6cf]
  • 🔧 chore: update yarn.lock [3457be5]
  • 🎨 style: set print width to 100 (old is 80) [dd57d3f]
  • ⬆️ chore: upgrade dependencies [46da4bc]

Miscellaneous

  • 📝 docs: update CHANGELOG [c29da8f]
  • 📝 docs: update READMEs [89d28d1]
  • 📝 docs: update CHANGELOG [fecbf5a]

1.0.23 (2021-11-28)

Added

  • ✨ feat(@algorithm.ts/findset): support EnhancedFindset (use through ) [da80941]
  • 👷‍♂️ chore: update ci configs [709dc6f]

Changed

  • ⚡ improve(findset): use Unit32Array instead of number[] to save memory and get better performance [a6d97d2]
  • ⬆️ chore: upgrade devDependencies [3f8b2d5]

Miscellaneous

  • improve(findset): add new member func 'initNode' to init a specify node in the findset [a93bc91]
  • [BREAKING] refactor: rename 'FindSet' to 'Findset' [5b8c25f]
  • 📝 docs(@algorithm.ts/roman): update README [d334490]
  • 📝 docs(@algorithm.ts/roman): update README [ba78363]
  • 📝 docs: update CHANGELOG [02213d0]

1.0.22 (2021-10-19)

Added

  • ✨ feat: implement '@algorithm.ts/roman' [fcc07fd]

Changed

  • ⬆️ chore: upgrade devDependencies [1dea6c1]

Miscellaneous

  • 📝 docs: fix invalid link references [ab06d7b]
  • 📝 docs: update CHANGELOG [fdc755b]

1.0.21 (2021-10-07)

Added

  • ✨ feat: implement '@algorithm.ts/sieve-totient' [38a939f]

Miscellaneous

  • 📝 docs: update READMEs [2e17b5b]
  • 📝 docs: update CHANGELOG [a33554d]

1.0.20 (2021-10-07)

Added

  • ✨ feat: implement '@algorithm.ts/sieve-prime' [fee8d9a]

Changed

  • ⚡ improve: prefer Unit32Array instead of number[] [eb890fe]

Miscellaneous

  • 📝 docs: update CHANGELOG [0c3ab92]

1.0.19 (2021-10-07)

Added

  • ✨ feat: implement '@algorithm.ts/manacher' [a2151f1]

Changed

  • ⬆️ chore: upgrade devDependencies [68cf3e1]

Miscellaneous

  • 📝 docs: update CHANGELOG [b617ec5]

1.0.18 (2021-09-21)

Added

  • ✨ feat(@algorithm.ts/calculate): support to perform bigint and decimal arithmetics [2371dab]

Changed

  • ⬆️ chore: upgrade devDependencies & fix linter warnings [4e110da]

Miscellaneous

  • 📝 docs: update READMEs [2168e61]
  • 📝 docs: update README [b13c7b2]
  • 📝 docs: update CHANGELOG [3f010b8]

1.0.17 (2021-09-20)

Added

  • ✨ feat: implement '@algorithm.ts/calculate' [22001ff]

Miscellaneous

  • 📝 docs: update READMEs [b30be1f]
  • 📝 docs: update CHANGELOG [9cd3f2d]

1.0.16 (2021-09-11)

Added

  • ✨ feat: implemented bigint versions of lower-bound and upper-bound [97846b1]

Miscellaneous

  • 📝 docs: update CHANGELOG [e27d876]

1.0.15 (2021-09-11)

Added

  • ✨ feat: implement '@algorithm.ts/upper-bound' [1bd4ef0]
  • ✨ feat: implement '@algorithm.ts/lower-bound' [b1cbb99]

Miscellaneous

  • 📝 docs: update README [ba86828]
  • 📝 docs: update README [aa74fd2]
  • 📝 docs: update CHANGELOG [f8e28f7]

1.0.14 (2021-09-08)

Added

  • ✨ feat: implement '@algorithm.ts/sliding-window' [bf4276b]
  • ✨ feat(trie): export new function 'hasPrefixMatched' [5bdb306]

Miscellaneous

  • 📝 docs(priority-queue): update README [1746090]
  • 📝 docs: update CHANGELOG [5dc4fd9]

1.0.13 (2021-09-06)

Added

  • ✨ feat: implemented '@algorithm.ts/gcd' [2b3c113]

Miscellaneous

  • 📝 docs: update README [3c5be84]
  • 📝 docs: update CHANGELOG [ba0a822]

1.0.12 (2021-08-29)

Added

  • ✨ feat: implement '@algorithm.ts/dijkstra' [9d61f0f]

Miscellaneous

  • 📝 docs: update CHANGELOG [188e1bc]

1.0.11 (2021-08-28)

Added

  • ✨ feat: implement '@algorithm.ts/trie' [39a26a1]

Miscellaneous

  • 📝 docs: update CHANGELOG [1acaaa3]

1.0.10 (2021-08-27)

Added

  • ✨ feat(binary-search-tree): export createBinaryIndexTree1Mod and createBinaryIndexTree2Mod [602aaaf]

Miscellaneous

  • 📝 docs: update CHANGELOG [dea9c50]

1.0.9 (2021-08-24)

Changed

  • 🎨 improve(dinic,isap,mcmf): totalEdges is not required [ba20cc9]

Miscellaneous

  • 📝 docs: update CHANGELOG [8d82092]

1.0.8 (2021-08-24)

Added

  • ✨ feat: implement '@algorithm.ts/mcmf' [1f7f8c7]
  • ✨ feat: implement '@algorithm.ts/dinic' [bb5ac22]
  • ✨ feat: implement '@algorithm.ts/isap' [a1d36ec]

Changed

  • 🎨 improve(isap, dinic): rename .maxflow to .maxFlow [bbf2590]
  • ⬆️ chore: upgrade devDependencies [a79aa1b]

Miscellaneous

  • 📝 docs: update README [1f5ce72]
  • 📝 docs: update READMEs [de2a217]

1.0.7 (2021-08-21)

Added

  • ✨ feat: implement '@algorithm.ts/circular-queue' [95e40f5]

Miscellaneous

  • improve(priority-queue): resize the array while initializing [5d6df88]
  • 🚧 improve(binary-search-tree): no longer necessary to specify the initial size when create a new BIT [8ec5f4d]
  • 📝 docs: update README [39901fb]

1.0.6 (2021-08-20)

Added

  • ✨ feat: implement '@algorithm.ts/findset' [0a23268]

Changed

  • ⬆️ chore: upgrade dev dependencies [25ed124]

Miscellaneous

  • 📝 docs: update README [bbd6fae]
  • 📝 docs: update README [0dfbb8d]
  • 📝 docs: update CHANGELOG [07fea47]

1.0.5 (2021-08-09)

Added

  • ✨ feat: implement '@algorithm.ts/binary-index-tree' [1440439]

Miscellaneous

  • 📝 docs: update READMEs [ec51481]
  • 📝 docs: update CHANGELOG [32f54c1]

1.0.4 (2021-08-03)

Added

  • ✨ feat(priority-queue): support build Priority Queue with O(N) complexity [a1d2455]

Miscellaneous

  • 📝 docs: update CHANGELOG [f8004d4]

1.0.3 (2021-08-03)

Added

  • ✨ feat: implement '@algorithm.ts/priority-queue' [6994a46]

Changed

  • ⬆️ chore: upgrade devDependencies [f9b7325]

Miscellaneous

  • 📝 docs: update CHANGELOG [f5f6d0c]

1.0.2 (2021-07-28)

Added

  • ✨ feat(sudoku): exports new utility func 'createSegmentCodeMap' [2322eef]

Changed

  • ⚡ improve(sudoku): improve performance on 'checkSudokuSolution' [e2350a0]
  • 🎨 rename(sudoku): rename type 'SudokuGameData' to 'SudokuData' [6ef309d]

Miscellaneous

  • 📝 docs: update CHANGELOG [df45e2c]

1.0.1 (2021-07-26)

Added

  • ✨ feat: impelemnt 'sudoku' [7f94624]
  • ✨ feat(knuth-shuffle): export utililty function 'randomInt' [ca51c82]
  • ✅ test(dlx): update tests [6d03d70]
  • ✨ feat: implement 'dlx' [0c4f7a9]

Changed

  • 🎨 improve(knuth-shuffle): support to shuffle sub-range of array [56ffc5c]

Removed

  • ➖ chore: remove unnecessary dependencies [5aaa280]

Miscellaneous

  • 📝 docs: update README [85145dc]

1.0.0 (2021-07-25)

Added

  • ✨ feat: implement 'knuth-shuffle' [58b39c5]
  • 🎉 initialize [a03a7e2]

Changed

  • 🚚 rename: move package from @guanghechen/* to @algorithm.ts/* [5534850]
  • ♿ improve(knuth-shuffle): add default export [f098256]

Miscellaneous

  • 📝 docs: update CHANGELOG [c23dbdd]
  • 📝 docs: update README [c00749b]
  • 📝 docs: add CHANGELOG [c946120]
  • 🔨 chore: allow to publish sub-packages with different versions [90db8aa]
  • 📝 docs: add README [18590b0]
  • 🔨 chore: add development configs [2aae64c]