Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package it.unimi.dsi.sux4j.bits;
 
 /*		 
  * Sux4J: Succinct data structures for Java
  *
  * Copyright (C) 2008-2014 Sebastiano Vigna 
  *
  *  This library is free software; you can redistribute it and/or modify it
  *  under the terms of the GNU Lesser General Public License as published by the Free
 *  Software Foundation; either version 3 of the License, or (at your option)
 *  any later version.
 *
 *  This library is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 */
A data structure providing selection over a bit array.

Selection is a basic building blocks for most succinct data structures. Usually, instances of this class class provide quick (e.g., constant time) selection.

There is some variance in the literature about the exact semantics of selection—in most cases, it is a matter of off-by-ones. This interface specifies a zero-based selection.

More precisely, select is applied to a bit vector in which bits positions are numbered starting from zero. Then, select(r) is the position of the leftmost bit set to one and preceded by r ones.

A number of equations link rank() and select():

  • rank(0)=0;
  • rank(length()) is the number of ones in the bit vector;
  • if r < rank(length()), then rank(select(r))==r;
  • if r &ge; rank(length()), then select(r)=-1;
  • if p &le; length(), then p&le;select(rank(p)), and equality holds iff there is a one at position p.
public interface Select extends Serializable {

Returns the position of the bit of given rank. Equivalently, returns the greatest position that is preceded by the specified number of ones.

Parameters:
rank a rank.
Returns:
the position of the bit of given rank; if no such position exists, &minus;1 is returned.
	public long selectlong rank );

Returns the bit vector indexed by this structure.

Note that you are not supposed to modify the returned vector.

Returns:
the bit vector indexed by this structure.
	public BitVector bitVector();

Returns the overall number of bits allocated by this structure.

Returns:
the overall number of bits allocated by this structure (not including the bits of the indexed vector).
	public long numBits();
New to GrepCode? Check out our FAQ X