public static int chunkContainingPos ( final long [ ] arr , final long pos ) { final int nominalLength = arr . length - 1 ; /* remember, arr contains an "extra" position */ assert nominalLength > 0 ; final long n = arr [ nominalLength ] ; assert 0 <= pos ; assert pos < n ; final int l = 0 ; final int r = nominalLength ; // the following three asserts should probably be retained since they ensure // that the necessary invariants hold at the beginning of the search assert l < r ; assert arr [ l ] <= pos ; assert pos < arr [ r ] ; return searchForChunkContainingPos ( arr , pos , l , r ) ; }
This is written in terms of a plain array to facilitate testing .