in reply to mapping lists

If your lists are large, linear-search algorithms will be very slow. Your program and the one by thinker use linear searches. You can find points in a sorted list much faster with a binary search, which is O(log n). The Search::Binary module provides a generic implementation. (The learning curve for that module looks a bit steep, however.)

Replies are listed 'Best First'.
Re: Re: mapping lists
by belg4mit (Prior) on Jan 24, 2003 at 19:55 UTC
    And how am I supposed to do a binary search for somethign that doesn't exist in the tree?

    --
    I'm not belgian but I play one on TV.

      It's not a problem for a binary search that the value does not exist in the tree. It will find the nearest place for it.

      Here is an excerpt from the binary search documentation:

      use Search::Binary; $pos = binary_search($min, $max, $val, $read, $handle, [$size]);

      "binary_search" implements a generic binary search algo­rithm returning the position of the first record whose index value is greater than or equal to $val.