Searches also neighbouring tiles until the maximum distance from the query point is reached
(minResolutionInMeter*regionAround). Set to 1 for to force avoiding a fall back, good if you
have strict performance and lookup-quality requirements. Default is 4.
424993
public LocationIndexTree setMaxRegionSearch(int numTiles) {
        if (numTiles < 1)
            throw new IllegalArgumentException("Region of location index must be at least 1 but was " + numTiles);

        // see #232
        if (numTiles % 2 == 1)
            numTiles++;

        this.maxRegionSearch = numTiles;
        return this;
    }
251474
def _check_boundaries(self, fragment):
        
        if not isinstance(fragment, SyncMapFragment):
            raise TypeError(u"fragment is not an instance of SyncMapFragment")
        interval = fragment.interval
        if not isinstance(interval, TimeInterval):
            raise TypeError(u"interval is not an instance of TimeInterval")
        if (self.begin is not None) and (interval.begin < self.begin):
            raise ValueError(u"interval.begin is before self.begin")
        if (self.end is not None) and (interval.end > self.end):
            raise ValueError(u"interval.end is after self.end")
476852
def AtMaximumDepth(self, search_depth):
    
    if self._key_path_segments is not None:
      if search_depth >= self._number_of_key_path_segments:
        return True

    return False
65191
function (bounds) {
        bounds = this.adjustBounds(bounds);
        var res = this.getServerResolution();
        var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
        var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h));
        var z = this.getZoomForResolution( res );

        var tileIndex = x + y * this.tierSizeInTiles[z].w + this.tileCountUpToTier[z];
        var path = "TileGroup" + Math.floor( (tileIndex) / 256 ) +
            "/" + z + "-" + x + "-" + y + ".jpg";
        var url = this.url;
        if (OpenLayers.Util.isArray(url)) {
            url = this.selectUrl(path, url);
        }
        return url + path;
    }
1023744
private Region find(long size) {
    validate(!VALIDATING || Long.bitCount(size) == 1);

    Region current = this.root;
    if ((current.available() & size) == 0) {
      //no region big enough for us...
      return null;
    } else {
      while (true) {
        if (current.left != null && (current.left.available() & size) != 0) {
          current = current.left;
        } else if ((current.availableHere() & size) != 0) {
          long mask = size - 1;
          long a = (current.start() + mask) & ~mask;
          return new Region(a, a + size - 1);
        } else if (current.right != null && (current.right.available() & size) != 0) {
          current = current.right;
        } else {
          throw new AssertionError();
        }
      }
    }
  }
661465
@Override
    public void _proximity(int proximity) {
        List<QueryToken> tokens = getCurrentWhereTokens();
        if (tokens.isEmpty()) {
            throw new IllegalStateException("Proximity can only be used right after search clause");
        }

        QueryToken whereToken = tokens.get(tokens.size() - 1);
        if (!(whereToken instanceof WhereToken)) {
            throw new IllegalStateException("Proximity can only be used right after search clause");
        }

        if (((WhereToken) whereToken).getWhereOperator() != WhereOperator.SEARCH) {
            throw new IllegalStateException("Proximity can only be used right after search clause");
        }

        if (proximity < 1) {
            throw new IllegalArgumentException("Proximity distance must be a positive number");
        }

        ((WhereToken) whereToken).getOptions().setProximity(proximity);
    }
65759
function(bounds) {
        var res = this.getServerResolution();
        var bbox = this.maxExtent;
        var size = this.tileSize;
        var tileX = Math.round((bounds.left - bbox.left) / (res * size.w));
        var tileY = Math.round((bounds.bottom - bbox.bottom) / (res * size.h));
        var tileZ = this.serverResolutions != null ?
            OpenLayers.Util.indexOf(this.serverResolutions, res) :
            this.map.getZoom();

        var components = [
            this.layername,
            OpenLayers.Number.zeroPad(tileZ, 2),
            OpenLayers.Number.zeroPad(parseInt(tileX / 1000000), 3),
            OpenLayers.Number.zeroPad((parseInt(tileX / 1000) % 1000), 3),
            OpenLayers.Number.zeroPad((parseInt(tileX) % 1000), 3),
            OpenLayers.Number.zeroPad(parseInt(tileY / 1000000), 3),
            OpenLayers.Number.zeroPad((parseInt(tileY / 1000) % 1000), 3),
            OpenLayers.Number.zeroPad((parseInt(tileY) % 1000), 3) + '.' + this.extension
        ];
        var path = components.join('/'); 
        var url = this.url;
        if (OpenLayers.Util.isArray(url)) {
            url = this.selectUrl(path, url);
        }
        url = (url.charAt(url.length - 1) == '/') ? url : url + '/';
        return url + path;
    }
850637
@Override
	protected int selectResolution( int widthTexture, int heightTexture, Size[] resolutions  ) {
		// just wanted to make sure this has been cleaned up
		timeOfLastUpdated = 0;

		// select the resolution here
		int bestIndex = -1;
		double bestAspect = Double.MAX_VALUE;
		double bestArea = 0;

		for( int i = 0; i < resolutions.length; i++ ) {
			Size s = resolutions[i];
			int width = s.getWidth();
			int height = s.getHeight();

			double aspectScore = Math.abs(width*height-targetResolution);

			if( aspectScore < bestAspect ) {
				bestIndex = i;
				bestAspect = aspectScore;
				bestArea = width*height;
			} else if( Math.abs(aspectScore-bestArea) <= 1e-8 ) {
				bestIndex = i;
				double area = width*height;
				if( area > bestArea ) {
					bestArea = area;
				}
			}
		}

		return bestIndex;
	}
1368922
protected void searchNode(P target, KdTree.Node n) {
		while( n != null) {
			checkBestDistance(n, target);

			if( n.isLeaf() )
				break;

			// select the most promising branch to investigate first
			KdTree.Node nearer,further;

			double splitValue = distance.valueAt( (P)n.point , n.split );

			if( distance.valueAt( target , n.split ) <= splitValue ) {
				nearer = n.left;
				further = n.right;
			} else {
				nearer = n.right;
				further = n.left;
			}

			// See if it is possible for 'further' to contain a better node
			double dx = splitValue - distance.valueAt(target, n.split );
			if( further != null && canImprove(dx*dx) ) {
				addToQueue(dx*dx, further, target );
			}

			n = nearer;
		}
	}
1113146
private synchronized int seekCountry(long ipAddress) {
        byte[] buf = new byte[2 * MAX_RECORD_LENGTH];
        int[] x = new int[2];
        int offset = 0;
        _check_mtime();
        for (int depth = 31; depth >= 0; depth--) {
            readNode(buf, x, offset);

            if ((ipAddress & (1 << depth)) > 0) {
                if (x[1] >= databaseSegments[0]) {
                    last_netmask = 32 - depth;
                    return x[1];
                }
                offset = x[1];
            } else {
                if (x[0] >= databaseSegments[0]) {
                    last_netmask = 32 - depth;
                    return x[0];
                }
                offset = x[0];
            }
        }
        throw new InvalidDatabaseException("Error seeking country while searching for "
                + ipAddress);
    }
1130560
public void setBounds(int minOccurs, int maxOccurs) {
    if (minOccurs < 0 || maxOccurs < -1)
      throw new IllegalArgumentException("Bounds cannot be negative");
    else if (maxOccurs > 0 && minOccurs > maxOccurs)
      throw new IllegalArgumentException("Minimum bounds less than maximum bounds");
    limits = new int[] { minOccurs, maxOccurs };
  }
1221739
protected void hunt(float val) {
		int lowerLimit = center;
		int upperLimit;
		int inc = 1;

		if (val >= x[lowerLimit] && ascend) {
			// hunt up
			for (; ; ) {
				upperLimit = lowerLimit + inc;
				// see if it is outside the table
				if (upperLimit >= size - 1) {
					upperLimit = size - 1;
					break;
				} else if (val < x[upperLimit] && ascend) {
					break;
				} else {
					lowerLimit = upperLimit;
					inc += inc;
				}
			}
		} else {
			// hunt down
			upperLimit = lowerLimit;
			for (; ; ) {
				lowerLimit = lowerLimit - inc;
				if (lowerLimit <= 0) {
					lowerLimit = 0;
					break;
				} else if (val >= x[lowerLimit] && ascend) {
					break;
				} else {
					upperLimit = lowerLimit;
					inc += inc;
				}
			}
		}

		bisectionSearch(val, lowerLimit, upperLimit);
	}
199720
function(resolution) {
        if(this.backBufferTimerId !== null) {
            this.removeBackBuffer();
        }
        var backBuffer = this.backBuffer;
        if(!backBuffer) {
            backBuffer = this.createBackBuffer();
            if(!backBuffer) {
                return;
            }
            if (resolution === this.gridResolution) {
                this.div.insertBefore(backBuffer, this.div.firstChild);
            } else {
                this.map.baseLayer.div.parentNode.insertBefore(backBuffer, this.map.baseLayer.div);
            }
            this.backBuffer = backBuffer;

            // set some information in the instance for subsequent
            // calls to applyBackBuffer where the same back buffer
            // is reused
            var topLeftTileBounds = this.grid[0][0].bounds;
            this.backBufferLonLat = {
                lon: topLeftTileBounds.left,
                lat: topLeftTileBounds.top
            };
            this.backBufferResolution = this.gridResolution;
        }
        
        var ratio = this.backBufferResolution / resolution;

        // scale the tiles inside the back buffer
        var tiles = backBuffer.childNodes, tile;
        for (var i=tiles.length-1; i>=0; --i) {
            tile = tiles[i];
            tile.style.top = ((ratio * tile._i * tile._h) | 0) + 'px';
            tile.style.left = ((ratio * tile._j * tile._w) | 0) + 'px';
            tile.style.width = Math.round(ratio * tile._w) + 'px';
            tile.style.height = Math.round(ratio * tile._h) + 'px';
        }

        // and position it (based on the grid's top-left corner)
        var position = this.getViewPortPxFromLonLat(
                this.backBufferLonLat, resolution);
        var leftOffset = this.map.layerContainerOriginPx.x;
        var topOffset = this.map.layerContainerOriginPx.y;
        backBuffer.style.left = Math.round(position.x - leftOffset) + 'px';
        backBuffer.style.top = Math.round(position.y - topOffset) + 'px';
    }
1169319
private double checkResolution(double resolution, ZoomOption zoomOption) {
		double allowedResolution = resolution;
		double maximumResolution = getMaximumResolution();
		double minimumResolution = getMinimumResolution();
		if (allowedResolution > maximumResolution) {
			allowedResolution = maximumResolution;
		} else if (allowedResolution < minimumResolution) {
			allowedResolution = minimumResolution;
		}

		if (zoomOption == ZoomOption.FREE) {
			return allowedResolution;
		}

		for (int i = 0; i < resolutions.size() - 1; i++) {
			double upper = resolutions.get(i);
			double lower = resolutions.get(i + 1);

			if (allowedResolution == upper) {
				return upper;
			} else if (allowedResolution == lower) {
				return lower;
			} else if (allowedResolution < upper && allowedResolution > lower) {
				switch (zoomOption) {
					case LEVEL_FIT:
						return upper;
					case LEVEL_CLOSEST:
						if (Math.abs(upper - allowedResolution) < Math.abs(allowedResolution - lower)) {
							return upper;
						} else {
							return lower;
						}
					default:
						return allowedResolution;
				}
			}
		}
		return allowedResolution;
	}
542958
function compareTiles( previousBest, tile ) {
    if ( !previousBest ) {
        return tile;
    }

    if ( tile.visibility > previousBest.visibility ) {
        return tile;
    } else if ( tile.visibility == previousBest.visibility ) {
        if ( tile.squaredDistance < previousBest.squaredDistance ) {
            return tile;
        }
    }

    return previousBest;
}
896394
@Override
    protected void searchStep() {
        // check: valid subset size range completely explored?
        if(validSubsetSizeRangeExplored()){
            // we are done
            stop();
        } else {
            int numAdd, numDel;
            if(isIncreasing()){
                // perform L additions
                numAdd = greedyMoves(l, singleAddNeigh);
                // perform number of deletions (<= R) that yields a delta of |L-R|,
                // taking into account the actual number of added items
                numDel = numAdd - getDelta();
                greedyMoves(numDel, singleDelNeigh);
            } else {
                // perform R deletions
                numDel = greedyMoves(r, singleDelNeigh);
                // perform number of additions (<= L) that yields a delta of |L-R|,
                // taking into account the actual number of deleted items
                numAdd = numDel - getDelta();
                greedyMoves(numAdd, singleAddNeigh);
            }
            if(numAdd == 0 || numDel == 0){
                stop();
            }
        }
    }
1047402
public void throwIfUnsupportedScan(Scan scan) {
    if (scan.getFilter() != null) {
      filterAdapter.throwIfUnsupportedFilter(scan, scan.getFilter());
    }

    if (scan.getMaxResultsPerColumnFamily() != UNSET_MAX_RESULTS_PER_COLUMN_FAMILY) {
      throw new UnsupportedOperationException(
          "Limiting of max results per column family is not supported.");
    }
  }