Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Exponential search/doc

From Official Streamlined Wiki

This is the documentation page for Module:Exponential search

Function list
L 7 — midPoint
L 11 — search

This module provides a generic exponential search algorithm. This kind of search can be useful when you want to find a key in some kind of sorted array, and you want to do it by checking as few array elements as possible. This could include situations like:

  • Finding the highest archive number in a set of archives without checking whether they all exist.
  • Finding the number of positional arguments in frame.args without having to expand the wikitext for each of them.

You shouldn't use this module if any of the following apply:

  1. You can use the Lua length operator to find what you need.
  2. Your array has any gaps in it. (In other words, any of the items before the final item is nil, e.g. {'foo', 'bar', nil, 'baz'}.) If you try and use this module on a sparse array, you might get an erroneous value.
  3. Your array has less then about 10 items in it. It's possible to use this module for those arrays, but you will access most of the array elements anyway (perhaps some of them twice), and your code will be more complicated than if you just used a for loop.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.