Proposed additions to Data.Map: lookupFloor and lookupCeiling

Twan van Laarhoven twanvl at gmail.com
Mon Mar 1 21:24:14 EST 2010


Sean Leather wrote:
>     -- | /O(log n)/. Find the greatest key that is smaller or equal
>     -- to the given target key.   This \"floor\" key is returned,
> 
>     -- | /O(log n)/. Find the smallest key that is greater or equal
>     -- to the given target key.   This \"ceiling\" key is returned,
> 
> It seems more intuitive to reverse the naming. The key parameter to 
> lookupFloor is actually the ceiling, and the key returned is the 
> greatest key less than or equal to the ceiling. Since there is no floor 
> involved here, I would call the function lookupCeiling.


As another point of reference, the Java TreeMap class provides [1]:

   floorKey(K key)
           Returns the greatest key less than or equal to the given key,
             or null if there is no such key.
   ceilingKey(K key)
           Returns the least key greater than or equal to the given key,
             or null if there is no such key.
   higherKey(K key)
           Returns the least key strictly greater than the given key,
             or null if there is no such key.
   lowerKey(K key)
           Returns the greatest key strictly less than the given key,
             or null if there is no such key.


My proposal would be to just call things as they are, and add the functions 
findGreater, findLess, findGreaterEqual and findLessEqual.


Twan


[1] http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html


More information about the Libraries mailing list