From: <mrp...@us...> - 2011-05-11 03:20:15
|
Revision: 4481 http://bigdata.svn.sourceforge.net/bigdata/?rev=4481&view=rev Author: mrpersonick Date: 2011-05-11 03:20:08 +0000 (Wed, 11 May 2011) Log Message: ----------- inline sids and reverse lookup Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/ChunkedArrayIterator.java Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ArrayAccessPath.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/Bits.java Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ArrayAccessPath.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ArrayAccessPath.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/relation/accesspath/ArrayAccessPath.java 2011-05-11 03:20:08 UTC (rev 4481) @@ -0,0 +1,196 @@ +/* +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.relation.accesspath; + +import java.util.Collections; + +import com.bigdata.bop.IPredicate; +import com.bigdata.btree.IIndex; +import com.bigdata.btree.ITupleIterator; +import com.bigdata.striterator.ChunkedArrayIterator; +import com.bigdata.striterator.ChunkedWrappedIterator; +import com.bigdata.striterator.IChunkedOrderedIterator; +import com.bigdata.striterator.IKeyOrder; + +/** + * An access path over an array of elements. + */ +public class ArrayAccessPath<E> implements IAccessPath<E> { + + private final IPredicate<E> predicate; + + private final IKeyOrder<E> keyOrder; + + /** + * Array of elements + */ + private final E[] e; + + /** + * Ctor variant does not specify the {@link #getPredicate()} or the + * {@link #getKeyOrder()} and those methods will throw an + * {@link UnsupportedOperationException} if invoked. + */ + public ArrayAccessPath(final E[] e) { + + this(e, null/* predicate */, null/* keyOrder */); + + } + + /** + * Note: the {@link #getPredicate()} and {@link #getKeyOrder()} and methods + * will throw an {@link UnsupportedOperationException} if the corresponding + * argument is null. + */ + public ArrayAccessPath(final E[] e, + final IPredicate<E> predicate, final IKeyOrder<E> keyOrder) { + + this.predicate = predicate; + + this.keyOrder = keyOrder; + + this.e = e; + + } + + /** + * @throws UnsupportedOperationException + * unless the caller specified an {@link IPredicate} to the + * ctor. + */ + public IPredicate<E> getPredicate() { + + if (predicate == null) + throw new UnsupportedOperationException(); + + return predicate; + + } + + /** + * @throws UnsupportedOperationException + * unless the caller specified an {@link IKeyOrder} to the ctor. + */ + public IKeyOrder<E> getKeyOrder() { + + if (keyOrder == null) + throw new UnsupportedOperationException(); + + return keyOrder; + + } + + /** + * @throws UnsupportedOperationException + * since no index is associated with this array + */ + public IIndex getIndex() { + + throw new UnsupportedOperationException(); + + } + + /** + * Returns <code>true</code> when the array of elements is empty. + */ + public boolean isEmpty() { + + return e.length == 0; + + } + + /** + * Returns the size of the array of elements. + */ + public long rangeCount(boolean exact) { + + return e.length; + + } + + /** + * @throws UnsupportedOperationException + * since no index is associated with this array + */ + public ITupleIterator<E> rangeIterator() { + + throw new UnsupportedOperationException(); + + } + + /** + * Visits the entire array of elements. + */ + public IChunkedOrderedIterator<E> iterator() { + + if (e.length == 0) { + return new ChunkedWrappedIterator<E>( + Collections.EMPTY_LIST.iterator()); + } + + return new ChunkedArrayIterator<E>(e); + + } + + /** + * Visits the array of elements up to the specified limit. + */ + public IChunkedOrderedIterator<E> iterator(final int limit, + final int capacity) { + + return iterator(0L/* offset */, limit, capacity); + + } + + /** + * Visits the array of elements from the specified offset up to the + * specified limit. + */ + @SuppressWarnings("unchecked") + public IChunkedOrderedIterator<E> iterator(final long offset, + final long limit, final int capacity) { + + if (e.length == 0) { + return new ChunkedWrappedIterator<E>( + Collections.EMPTY_LIST.iterator()); + } + + final E[] a = (E[]) java.lang.reflect.Array.newInstance( + e[0].getClass(), (int) limit); + + System.arraycopy(e, (int) offset, a, 0, (int) limit); + + return new ChunkedArrayIterator<E>(a); + + } + + /** + * Does nothing and always returns ZERO(0). + */ + public long removeAll() { + + return 0L; + + } + +} Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/ChunkedArrayIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/ChunkedArrayIterator.java 2011-05-11 03:19:09 UTC (rev 4480) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/striterator/ChunkedArrayIterator.java 2011-05-11 03:20:08 UTC (rev 4481) @@ -74,6 +74,18 @@ * * @param a * The array of elements. + */ + public ChunkedArrayIterator(final E[] a) { + + this(a.length, a, null); + + } + + /** + * An iterator that visits the elements in the given array. + * + * @param a + * The array of elements. * @param n * The #of entries in <i>a</i> that are valid. * @param keyOrder Added: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/Bits.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/Bits.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/util/Bits.java 2011-05-11 03:20:08 UTC (rev 4481) @@ -0,0 +1,136 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2011. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.util; + +import it.unimi.dsi.bits.BitVector; + +import java.nio.ByteBuffer; + + +/** + * Simple helper class to work with bits inside a byte. Useful for classes + * that have a lot of boolean properties or pointers to enums that can be + * more compactly represented as a series of bit flags. See SPO. + * + * @author mikepersonick + */ +public class Bits { + + /** + * Set a bit inside a byte. + * + * @param bits + * the original byte + * @param i + * the bit index (0 through 7) + * @param bit + * the bit value + * @return + * the new byte + */ + public static byte set(final byte bits, final int i, final boolean bit) { + + // check to see if bits[i] == bit already, if so, nothing to do + // also does range check on i + if (get(bits, i) == bit) + return bits; + + byte b = bits; + if (bit) { + b = (byte) (b | (0x1 << i)); + } else { + b = (byte) (b & ~(0x1 << i)); + } + return b; + + } + + /** + * Get a bit from inside a byte. + * + * @param bits + * the byte + * @param i + * the bit index (0 through 7) + * @return + * the bit value + */ + public static boolean get(final byte bits, final int i) { + + if (i < 0 || i > 7) { + throw new IndexOutOfBoundsException(); + } + + return (bits & (0x1 << i)) != 0; + + } + + /** + * Get a new byte, masking off all but the bits specified by m. + * + * @param bits + * the original byte + * @param m + * the bits to keep, all others will be masked + * @return + * the new byte + */ + public static byte mask(final byte bits, final int... m) { + + byte b = 0; + + for (int i = 0; i < m.length; i++) { + + if (m[i] < 0 || m[i] > 7) { + throw new IndexOutOfBoundsException(); + } + + b |= (0x1 << m[i]); + + } + + b &= bits; + + return b; + + } + + /** + * Useful for debugging. + * + * @param bits + * the byte + * @return + * the unsigned binary string representation + */ + public static String toString(final byte bits) { + + final byte[] d = new byte[] { bits }; + final ByteBuffer b = ByteBuffer.wrap(d); + final BitVector v = new ByteBufferBitVector(b); + return v.toString(); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |