Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 977D7200C10 for ; Thu, 19 Jan 2017 10:04:45 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9639A160B42; Thu, 19 Jan 2017 09:04:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CBA97160B5B for ; Thu, 19 Jan 2017 10:04:44 +0100 (CET) Received: (qmail 16274 invoked by uid 500); 19 Jan 2017 09:04:44 -0000 Mailing-List: contact commits-help@kylin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@kylin.apache.org Delivered-To: mailing list commits@kylin.apache.org Received: (qmail 16080 invoked by uid 99); 19 Jan 2017 09:04:43 -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; Thu, 19 Jan 2017 09:04:43 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B1FA1DFDF1; Thu, 19 Jan 2017 09:04:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lidong@apache.org To: commits@kylin.apache.org Date: Thu, 19 Jan 2017 09:04:47 -0000 Message-Id: <25bb23d157b4443e836cf0980afecfb5@git.apache.org> In-Reply-To: <182501c139d649d1b820c4b1ce8df97a@git.apache.org> References: <182501c139d649d1b820c4b1ce8df97a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/12] kylin git commit: Opt some constant value archived-at: Thu, 19 Jan 2017 09:04:45 -0000 Opt some constant value Signed-off-by: shaofengshi Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/6e303767 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/6e303767 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/6e303767 Branch: refs/heads/master-cdh5.7 Commit: 6e30376752d95bafa4a1773d39c2f798f75c35a7 Parents: 837bd82 Author: xiefan46 <958034172@qq.com> Authored: Tue Jan 17 10:34:20 2017 +0800 Committer: shaofengshi Committed: Wed Jan 18 16:28:05 2017 +0800 ---------------------------------------------------------------------- .../apache/kylin/dict/TrieDictionaryForest.java | 77 +++++++++++++++----- 1 file changed, 57 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/6e303767/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java index 04292d2..1023892 100755 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java @@ -51,6 +51,14 @@ public class TrieDictionaryForest extends CacheDictionary { private ArrayList maxValue; + private int minId; + + private int maxId; + + private int sizeOfId; + + private int sizeOfValue; + public TrieDictionaryForest() { // default constructor for Writable interface } @@ -65,42 +73,28 @@ public class TrieDictionaryForest extends CacheDictionary { this.accuOffset = accuOffset; this.bytesConvert = bytesConverter; this.baseId = baseId; - initMaxValue(); + initConstantValue(); initForestCache(); } @Override public int getMinId() { - if (trees.isEmpty()) - return baseId; - return trees.get(0).getMinId() + baseId; + return this.minId; } @Override public int getMaxId() { - if (trees.isEmpty()) - return baseId - 1; - int index = trees.size() - 1; - int id = accuOffset.get(index) + trees.get(index).getMaxId() + baseId; - return id; + return this.maxId; } @Override public int getSizeOfId() { - if (trees.isEmpty()) - return 1; - int maxOffset = accuOffset.get(accuOffset.size() - 1); - TrieDictionary lastTree = trees.get(trees.size() - 1); - int sizeOfId = BytesUtil.sizeForValue(baseId + maxOffset + lastTree.getMaxId() + 1L); - return sizeOfId; + return this.sizeOfId; } @Override public int getSizeOfValue() { - int maxValue = 0; - for (TrieDictionary tree : trees) - maxValue = Math.max(maxValue, tree.getSizeOfValue()); - return maxValue; + return this.sizeOfValue; } @Override @@ -340,7 +334,16 @@ public class TrieDictionaryForest extends CacheDictionary { } } - private void initMaxValue() throws IllegalStateException { + private void initConstantValue() throws IllegalStateException { + initMaxValueForEachTrie(); + initMaxId(); + initMinId(); + initSizeOfId(); + initSizeOfValue(); + } + + private void initMaxValueForEachTrie(){ + //init max value this.maxValue = new ArrayList<>(); if (this.trees == null || trees.isEmpty()) { return; @@ -353,6 +356,40 @@ public class TrieDictionaryForest extends CacheDictionary { } } + private void initMaxId(){ + if (trees.isEmpty()) { + this.maxId = baseId - 1; + return; + } + int index = trees.size() - 1; + this.maxId = accuOffset.get(index) + trees.get(index).getMaxId() + baseId; + } + + private void initMinId(){ + if (trees.isEmpty()) { + this.minId = baseId; + return; + } + this.minId = trees.get(0).getMinId() + baseId; + } + + private void initSizeOfId(){ + if (trees.isEmpty()){ + this.sizeOfId = 1; + return; + } + int maxOffset = accuOffset.get(accuOffset.size() - 1); + TrieDictionary lastTree = trees.get(trees.size() - 1); + this.sizeOfId = BytesUtil.sizeForValue(baseId + maxOffset + lastTree.getMaxId() + 1L); + } + + private void initSizeOfValue(){ + int maxValue = 0; + for (TrieDictionary tree : trees) + maxValue = Math.max(maxValue, tree.getSizeOfValue()); + this.sizeOfValue = maxValue; + } + private void initForestCache() { enableCache(); for (TrieDictionary tree : trees) { //disable duplicate cache