All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.lucene.index.MultiBits Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
/*
 * COPIED FROM APACHE LUCENE 4.7.2
 *
 * Git URL: [email protected]:apache/lucene.git, tag: releases/lucene-solr/4.7.2, path: lucene/core/src/java
 *
 * (see https://issues.apache.org/jira/browse/OAK-10786 for details)
 */

package org.apache.lucene.index;

import org.apache.lucene.util.Bits;

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Concatenates multiple Bits together, on every lookup.
 *
 * 

NOTE: This is very costly, as every lookup must * do a binary search to locate the right sub-reader. * * @lucene.experimental */ final class MultiBits implements Bits { private final Bits[] subs; // length is 1+subs.length (the last entry has the maxDoc): private final int[] starts; private final boolean defaultValue; public MultiBits(Bits[] subs, int[] starts, boolean defaultValue) { assert starts.length == 1+subs.length; this.subs = subs; this.starts = starts; this.defaultValue = defaultValue; } private boolean checkLength(int reader, int doc) { final int length = starts[1+reader]-starts[reader]; assert doc - starts[reader] < length: "doc=" + doc + " reader=" + reader + " starts[reader]=" + starts[reader] + " length=" + length; return true; } @Override public boolean get(int doc) { final int reader = ReaderUtil.subIndex(doc, starts); assert reader != -1; final Bits bits = subs[reader]; if (bits == null) { return defaultValue; } else { assert checkLength(reader, doc); return bits.get(doc-starts[reader]); } } @Override public String toString() { StringBuilder b = new StringBuilder(); b.append(subs.length + " subs: "); for(int i=0;i© 2015 - 2024 Weber Informatics LLC | Privacy Policy