start < limit
, returns a short key in [start,limit).
* Simple comparator implementations should return start unchanged,
*
* @param start
* @param limit
* @return
*/
byte[] findShortestSeparator(byte[] start, byte[] limit);
/**
* returns a 'short key' where the 'short key' >= key.
* Simple comparator implementations should return key unchanged,
*
* @param key
*/
byte[] findShortSuccessor(byte[] key);
}
leveldb-0.7/leveldb-api/src/main/java/org/iq80/leveldb/DBException.java 0000664 0000000 0000000 00000002176 12274606001 0025615 0 ustar 00root root 0000000 0000000 /**
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed 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.
*/
package org.iq80.leveldb;
/**
* @author Hiram Chirino
*/
public class DBException extends RuntimeException {
public DBException() {
}
public DBException(String s) {
super(s);
}
public DBException(String s, Throwable throwable) {
super(s, throwable);
}
public DBException(Throwable throwable) {
super(throwable);
}
}
leveldb-0.7/leveldb-api/src/main/java/org/iq80/leveldb/DBFactory.java 0000664 0000000 0000000 00000002147 12274606001 0025264 0 ustar 00root root 0000000 0000000 /**
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed 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.
*/
package org.iq80.leveldb;
import java.io.File;
import java.io.IOException;
/**
* @author Hiram Chirino
*/
public interface DBFactory {
public DB open(File path, Options options) throws IOException;
public void destroy(File path, Options options) throws IOException;
public void repair(File path, Options options) throws IOException;
}
leveldb-0.7/leveldb-api/src/main/java/org/iq80/leveldb/DBIterator.java 0000664 0000000 0000000 00000003657 12274606001 0025455 0 ustar 00root root 0000000 0000000 /**
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed 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.
*/
package org.iq80.leveldb;
import java.io.Closeable;
import java.util.Iterator;
import java.util.Map;
/**
* @author Hiram Chirino
*/
public interface DBIterator extends Iterator{key}={value}
.
*/
@Override
public String toString()
{
return key + "=" + value;
}
}
}
leveldb-0.7/leveldb/src/main/java/org/iq80/leveldb/impl/SequenceNumber.java 0000664 0000000 0000000 00000003116 12274606001 0026557 0 ustar 00root root 0000000 0000000 /**
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed 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.
*/
package org.iq80.leveldb.impl;
import com.google.common.base.Preconditions;
public final class SequenceNumber
{
// We leave eight bits empty at the bottom so a type and sequence#
// can be packed together into 64-bits.
public static final long MAX_SEQUENCE_NUMBER = ((0x1L << 56) - 1);
public static long packSequenceAndValueType(long sequence, ValueType valueType)
{
Preconditions.checkArgument(sequence <= MAX_SEQUENCE_NUMBER, "Sequence number is greater than MAX_SEQUENCE_NUMBER");
Preconditions.checkNotNull(valueType, "valueType is null");
return (sequence << 8) | valueType.getPersistentId();
}
public static ValueType unpackValueType(long num)
{
return ValueType.getValueTypeByPersistentId((byte) num);
}
public static long unpackSequenceNumber(long num)
{
return num >>> 8;
}
}
leveldb-0.7/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotImpl.java 0000664 0000000 0000000 00000004356 12274606001 0026266 0 ustar 00root root 0000000 0000000 /**
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed 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.
*/
package org.iq80.leveldb.impl;
import org.iq80.leveldb.Snapshot;
import java.util.concurrent.atomic.AtomicBoolean;
public class SnapshotImpl implements Snapshot
{
private final AtomicBoolean closed = new AtomicBoolean();
private final Version version;
private final long lastSequence;
SnapshotImpl(Version version, long lastSequence)
{
this.version = version;
this.lastSequence = lastSequence;
this.version.retain();
}
@Override
public void close()
{
// This is an end user API.. he might screw up and close multiple times.
// but we don't want the version reference count going bad.
if(closed.compareAndSet(false, true)) {
this.version.release();
}
}
public long getLastSequence() {
return lastSequence;
}
public Version getVersion() {
return version;
}
@Override
public String toString() {
return Long.toString(lastSequence);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SnapshotImpl snapshot = (SnapshotImpl) o;
if (lastSequence != snapshot.lastSequence) return false;
if (!version.equals(snapshot.version)) return false;
return true;
}
@Override
public int hashCode() {
int result = version.hashCode();
result = 31 * result + (int) (lastSequence ^ (lastSequence >>> 32));
return result;
}
}
leveldb-0.7/leveldb/src/main/java/org/iq80/leveldb/impl/SnapshotSeekingIterator.java 0000664 0000000 0000000 00000007302 12274606001 0030456 0 ustar 00root root 0000000 0000000 /**
* Copyright (C) 2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed 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.
*/
package org.iq80.leveldb.impl;
import com.google.common.collect.Maps;
import org.iq80.leveldb.util.AbstractSeekingIterator;
import org.iq80.leveldb.util.DbIterator;
import org.iq80.leveldb.util.Slice;
import java.util.Comparator;
import java.util.Map.Entry;
public final class SnapshotSeekingIterator extends AbstractSeekingIteratorname | *offset | *length | *description | *
---|---|---|---|
entries | *4 | *vary | *Entries in order by key | *
restart index | *vary | *4 * restart count | *Index of prefix compression restarts | *
restart count | *0 | *4 | *Number of prefix compression restarts (used as index into entries) | *
name | *offset | *length | *description | *
---|---|---|---|
shared key length | *0 | *vary | *variable length encoded int: size of shared key prefix with the key from the previous entry | *
non-shared key length | *vary | *vary | *variable length encoded int: size of non-shared key suffix in this entry | *
value length | *vary | *vary | *variable length encoded int: size of value in this entry | *
non-shared key | *vary | *non-shared key length | *non-shared key data | *
value | *vary | *value length | *value data | *
A common interface for internal iterators.
* * @author Hiram Chirino */ public interface InternalIterator extends SeekingIterator