Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0A8601835A for ; Tue, 19 Jan 2016 19:27:40 +0000 (UTC) Received: (qmail 52076 invoked by uid 500); 19 Jan 2016 19:27:40 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 52012 invoked by uid 500); 19 Jan 2016 19:27:39 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 52001 invoked by uid 99); 19 Jan 2016 19:27:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jan 2016 19:27:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9E836E00C5; Tue, 19 Jan 2016 19:27:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kturner@apache.org To: commits@accumulo.apache.org Message-Id: <845a5731f58547d18120e526efeffb6a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: accumulo git commit: ACCUMULO-4111: add float lexicoder Date: Tue, 19 Jan 2016 19:27:39 +0000 (UTC) Repository: accumulo Updated Branches: refs/heads/master f7b9fd40a -> 702ea54f6 ACCUMULO-4111: add float lexicoder Signed-off-by: Keith Turner Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/702ea54f Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/702ea54f Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/702ea54f Branch: refs/heads/master Commit: 702ea54f69c4568bc707d4134fa46d13bd429fd0 Parents: f7b9fd4 Author: Wil Selwood Authored: Thu Jan 14 13:37:43 2016 +0000 Committer: Keith Turner Committed: Tue Jan 19 12:18:04 2016 -0500 ---------------------------------------------------------------------- .../core/client/lexicoder/FloatLexicoder.java | 61 ++++++++++++++++++++ .../client/lexicoder/FloatLexicoderTest.java | 45 +++++++++++++++ 2 files changed, 106 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/702ea54f/core/src/main/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoder.java b/core/src/main/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoder.java new file mode 100644 index 0000000..50c6205 --- /dev/null +++ b/core/src/main/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoder.java @@ -0,0 +1,61 @@ +/* + * 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. + */ +package org.apache.accumulo.core.client.lexicoder; + +import org.apache.accumulo.core.client.lexicoder.impl.AbstractLexicoder; +import org.apache.accumulo.core.iterators.ValueFormatException; + +/** + * A lexicoder for preserving the native Java sort order of Float values. + * + * @since 1.8.0 + */ +public class FloatLexicoder extends AbstractLexicoder { + + private UIntegerLexicoder intEncoder = new UIntegerLexicoder(); + + @Override + public byte[] encode(Float f) { + int i = Float.floatToRawIntBits(f); + if (i < 0) { + i = ~i; + } else { + i = i ^ 0x80000000; + } + + return intEncoder.encode(i); + } + + @Override + public Float decode(byte[] b) { + // This concrete implementation is provided for binary compatibility with 1.6; it can be removed in 2.0. See ACCUMULO-3789. + return super.decode(b); + } + + @Override + protected Float decodeUnchecked(byte[] b, int offset, int len) throws ValueFormatException { + int i = intEncoder.decodeUnchecked(b, offset, len); + if (i < 0) { + i = i ^ 0x80000000; + } else { + i = ~i; + } + + return Float.intBitsToFloat(i); + } + +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/702ea54f/core/src/test/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoderTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoderTest.java b/core/src/test/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoderTest.java new file mode 100644 index 0000000..7ac683a --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/client/lexicoder/FloatLexicoderTest.java @@ -0,0 +1,45 @@ +/* + * 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. + */ +package org.apache.accumulo.core.client.lexicoder; + +import org.apache.accumulo.core.client.lexicoder.impl.AbstractLexicoderTest; + +import java.util.Arrays; + +/** + * + */ +public class FloatLexicoderTest extends AbstractLexicoderTest { + + public void testSortOrder() { + assertSortOrder( + new FloatLexicoder(), + Arrays.asList(Float.MIN_VALUE, Float.MAX_VALUE, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, 0.0F, 0.01F, 0.001F, 1.0F, -1.0F, -1.1F, -1.01F, + Math.nextUp(Float.NEGATIVE_INFINITY), Math.nextAfter(0.0F, Float.NEGATIVE_INFINITY), Math.nextAfter(Float.MAX_VALUE, Float.NEGATIVE_INFINITY))); + + } + + public void testDecode() { + assertDecodes(new FloatLexicoder(), Float.MIN_VALUE); + assertDecodes(new FloatLexicoder(), Math.nextUp(Float.NEGATIVE_INFINITY)); + assertDecodes(new FloatLexicoder(), -1.0F); + assertDecodes(new FloatLexicoder(), 0.0F); + assertDecodes(new FloatLexicoder(), 1.0F); + assertDecodes(new FloatLexicoder(), Math.nextAfter(Float.POSITIVE_INFINITY, 0.0F)); + assertDecodes(new FloatLexicoder(), Float.MAX_VALUE); + } +}