Skip to content

Commit

Permalink
Revert 'Make working with new bytes' and a couple of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
leventov committed Jul 1, 2015
1 parent a61ea22 commit 5c8f737
Show file tree
Hide file tree
Showing 41 changed files with 5,496 additions and 5,712 deletions.
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<groupId>net.openhft</groupId> <groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId> <artifactId>chronicle-bom</artifactId>
<type>pom</type> <type>pom</type>
<version>1.3.3-SNAPSHOT</version> <version>1.4.0</version>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>


Expand Down Expand Up @@ -90,7 +90,6 @@
<dependency> <dependency>
<groupId>net.openhft</groupId> <groupId>net.openhft</groupId>
<artifactId>chronicle-bytes</artifactId> <artifactId>chronicle-bytes</artifactId>
<version>1.0.5-alpha</version>
</dependency> </dependency>


<dependency> <dependency>
Expand Down Expand Up @@ -118,11 +117,6 @@
<artifactId>pax-url-aether</artifactId> <artifactId>pax-url-aether</artifactId>
</dependency> </dependency>


<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-network</artifactId>
</dependency>

<!-- test dependencies --> <!-- test dependencies -->


<dependency> <dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/openhft/chronicle/hash/AbstractData.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* but Java 8 doesn't allow to override {@code Object}'s methods by default implementations * but Java 8 doesn't allow to override {@code Object}'s methods by default implementations
* in interfaces. * in interfaces.
*/ */
public abstract class AbstractData<V, T> implements Data<V, T> { public abstract class AbstractData<V> implements Data<V> {


/** /**
* Constructor for use by subclasses. * Constructor for use by subclasses.
Expand All @@ -49,7 +49,7 @@ public int hashCode() {
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj != null && return obj != null &&
obj instanceof Data && obj instanceof Data &&
Data.bytesEquivalent(this, (Data<?, ?>) obj); Data.bytesEquivalent(this, (Data<?>) obj);
} }


/** /**
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public interface ChronicleHash<K, C extends KeyContext<K>, EQC extends ExternalH
* @param key the queried key as {@code Data} * @param key the queried key as {@code Data}
* @return the context to perform operations with the key * @return the context to perform operations with the key
*/ */
@NotNull EQC queryContext(Data<K, ?> key); @NotNull EQC queryContext(Data<K> key);


/** /**
* Checks the given predicate on each entry in this {@code ChronicleHash} until all entries * Checks the given predicate on each entry in this {@code ChronicleHash} until all entries
Expand Down
56 changes: 16 additions & 40 deletions src/main/java/net/openhft/chronicle/hash/Data.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@


package net.openhft.chronicle.hash; package net.openhft.chronicle.hash;


import net.openhft.chronicle.bytes.*;
import net.openhft.chronicle.algo.hashing.LongHashFunction; import net.openhft.chronicle.algo.hashing.LongHashFunction;
import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.bytes.RandomDataOutput;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;


import static net.openhft.chronicle.algo.bytes.Access.checkedRandomDataInputAccess;

/** /**
* Dual bytes/object access to keys/values/elements. * Dual bytes/object access to keys/values/elements.
* *
* <p>Bytes access: {@link #access()} + {@link #handle()} + {@link #offset()} + {@link #size()}. * <p>Bytes access: {@link #bytes()} + {@link #offset()} + {@link #size()}.
* *
* <p>Object access: {@link #get()}. * <p>Object access: {@link #get()}.
* *
Expand All @@ -34,19 +38,10 @@
* accordingly. * accordingly.
* *
* @param <V> type of the accessed objects * @param <V> type of the accessed objects
* @param <T> type of the handle for bytes access
*/ */
public interface Data<V, T> { public interface Data<V> {

/**
* Returns access to the value's bytes.
*/
ReadAccess<T> access();


/** RandomDataInput bytes();
* Returns a handle to access the value's bytes.
*/
T handle();


/** /**
* Returns the offset to the value's bytes. * Returns the offset to the value's bytes.
Expand All @@ -59,33 +54,15 @@ public interface Data<V, T> {
long size(); long size();


default long hash(LongHashFunction f) { default long hash(LongHashFunction f) {
return f.hash(handle(), access(), offset(), size()); return f.hash(bytes(), checkedRandomDataInputAccess(), offset(), size());
}

default <T2> boolean equivalent(ReadAccess<T2> access, T2 handle, long offset) {
return Access.equivalent(access(), handle(), offset(), access, handle, offset, size());
}

default <S, T2, A extends ReadAccess<T2>> boolean equivalent(
Accessor<S, T2, A> accessor, S source, long index) {
return equivalent(accessor.access(source), accessor.handle(source),
accessor.offset(source, index));
}

default <T2> void writeTo(WriteAccess<T2> targetAccess, T2 target, long targetOffset) {
Access.copy(access(), handle(), offset(), targetAccess, target, targetOffset, size());
} }


default <T2> void writeTo(StreamingDataOutput<?, ?, T2> output) { default boolean equivalent(RandomDataInput source, long sourceOffset) {
long offset = output.accessPositionOffset(); return BytesUtil.bytesEqual(source, sourceOffset, bytes(), offset(), size());
output.skip(size());
writeTo(output.access(), output.accessHandle(), offset);
} }


default <S, T2, A extends WriteAccess<T2>> void writeTo( default void writeTo(RandomDataOutput target, long targetOffset) {
Accessor<S, T2, A> targetAccessor, S target, long index) { target.write(targetOffset, bytes(), offset(), size());
writeTo(targetAccessor.access(target), targetAccessor.handle(target),
targetAccessor.offset(target, index));
} }


/** /**
Expand All @@ -102,10 +79,9 @@ default <S, T2, A extends WriteAccess<T2>> void writeTo(
*/ */
V getUsing(@Nullable V usingInstance); V getUsing(@Nullable V usingInstance);


static <T1, T2> boolean bytesEquivalent(Data<?, T1> v1, Data<?, T2> v2) { static boolean bytesEquivalent(Data<?> d1, Data<?> d2) {
if (v1.size() != v2.size()) if (d1.size() != d2.size())
return false; return false;
return Access.equivalent(v1.access(), v1.handle(), v1.offset(), return BytesUtil.bytesEqual(d1.bytes(), d1.offset(), d2.bytes(), d2.offset(), d1.size());
v2.access(), v2.handle(), v2.offset(), v1.size());
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public interface HashAbsentEntry<K> {
* Returns the key is going to be inserted into the {@code ChronicleHash}. * Returns the key is going to be inserted into the {@code ChronicleHash}.
*/ */
@NotNull @NotNull
Data<K, ?> absentKey(); Data<K> absentKey();
} }
2 changes: 1 addition & 1 deletion src/main/java/net/openhft/chronicle/hash/HashEntry.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface HashEntry<K> {
* Returns the entry key. * Returns the entry key.
*/ */
@NotNull @NotNull
Data<K, ?> key(); Data<K> key();


/** /**
* Removes the entry from the {@code ChronicleHash}. * Removes the entry from the {@code ChronicleHash}.
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public interface HashQueryContext<K> extends HashContext<K>, InterProcessReadWri
/** /**
* Returns the queried key as a {@code Data}. * Returns the queried key as a {@code Data}.
*/ */
Data<K, ?> queriedKey(); Data<K> queriedKey();


/** /**
* Returns the entry context, if the entry with the queried key is <i>present</i> * Returns the entry context, if the entry with the queried key is <i>present</i>
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,50 +18,48 @@


package net.openhft.chronicle.hash.impl; package net.openhft.chronicle.hash.impl;


import net.openhft.chronicle.bytes.ReadAccess; import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.hash.AbstractData; import net.openhft.chronicle.hash.AbstractData;
import net.openhft.lang.io.DirectBytes; import net.openhft.lang.io.DirectBytes;
import net.openhft.lang.io.DirectStore; import net.openhft.lang.io.DirectStore;
import net.openhft.lang.io.serialization.JDKObjectSerializer; import net.openhft.lang.io.serialization.JDKObjectSerializer;


import static net.openhft.chronicle.hash.impl.JavaLangBytesAccessors.uncheckedBytesAccessor; public abstract class CopyingInstanceData<I> extends AbstractData<I> {


public abstract class CopyingInstanceData<I, T> extends AbstractData<I, T> { private final JavaLangBytesReusableBytesStore bytesStore =
new JavaLangBytesReusableBytesStore();


public static DirectBytes getBuffer(DirectBytes b, long capacity) { public DirectBytes getBuffer(DirectBytes b, long capacity) {
if (b != null) { if (b != null) {
if (b.capacity() >= capacity) { if (b.capacity() >= capacity) {
return (DirectBytes) b.clear(); return (DirectBytes) b.clear();
} else { } else {
DirectStore store = (DirectStore) b.store(); DirectStore store = (DirectStore) b.store();
store.resize(capacity, false); store.resize(capacity, false);
return store.bytes(); DirectBytes bytes = store.bytes();
bytesStore.setBytes(bytes);
return bytes;
} }
} else { } else {
return new DirectStore(JDKObjectSerializer.INSTANCE, Math.max(1, capacity), true) DirectBytes bytes = new DirectStore(JDKObjectSerializer.INSTANCE,
.bytes(); Math.max(1, capacity), true).bytes();
bytesStore.setBytes(bytes);
return bytes;
} }
} }


public abstract I instance();

public abstract DirectBytes buffer();

@Override @Override
public ReadAccess<T> access() { public RandomDataInput bytes() {
//noinspection unchecked return bytesStore;
return (ReadAccess<T>) uncheckedBytesAccessor(buffer()).access(buffer());
} }


@Override public abstract I instance();
public T handle() {
//noinspection unchecked public abstract DirectBytes buffer();
return (T) uncheckedBytesAccessor(buffer()).handle(buffer());
}


@Override @Override
public long offset() { public long offset() {
return uncheckedBytesAccessor(buffer()).offset(buffer(), 0); return 0;
} }


@Override @Override
Expand Down

This file was deleted.

Loading

0 comments on commit 5c8f737

Please sign in to comment.