From e158e9249726050fcd2c28ff4376d2bbd4aa8072 Mon Sep 17 00:00:00 2001 From: godotg Date: Sat, 2 Sep 2023 19:17:15 +0800 Subject: [PATCH] ref[move]: move hash to net package --- .../ConsistentHashConsumerLoadBalancer.java | 2 +- .../com/zfoo/net/util}/ConsistentHash.java | 3 +- .../java/com/zfoo/net/util}/HashUtils.java | 3 +- .../zfoo/net/util}/ConsistentHashTest.java | 2 +- .../com/zfoo/util/math/Combinatorics.java | 55 ------------------- .../com/zfoo/util/math/dfa/WordTreeTest.java | 44 --------------- 6 files changed, 4 insertions(+), 105 deletions(-) rename {util/src/main/java/com/zfoo/util/math => net/src/main/java/com/zfoo/net/util}/ConsistentHash.java (98%) rename {util/src/main/java/com/zfoo/util/math => net/src/main/java/com/zfoo/net/util}/HashUtils.java (98%) rename {util/src/test/java/com/zfoo/util/math => net/src/test/java/com/zfoo/net/util}/ConsistentHashTest.java (99%) delete mode 100644 util/src/main/java/com/zfoo/util/math/Combinatorics.java delete mode 100644 util/src/test/java/com/zfoo/util/math/dfa/WordTreeTest.java diff --git a/net/src/main/java/com/zfoo/net/consumer/balancer/ConsistentHashConsumerLoadBalancer.java b/net/src/main/java/com/zfoo/net/consumer/balancer/ConsistentHashConsumerLoadBalancer.java index 8947b665..d6203ce6 100644 --- a/net/src/main/java/com/zfoo/net/consumer/balancer/ConsistentHashConsumerLoadBalancer.java +++ b/net/src/main/java/com/zfoo/net/consumer/balancer/ConsistentHashConsumerLoadBalancer.java @@ -22,7 +22,7 @@ import com.zfoo.protocol.collection.CollectionUtils; import com.zfoo.protocol.exception.RunException; import com.zfoo.protocol.model.Pair; import com.zfoo.protocol.registration.ProtocolModule; -import com.zfoo.util.math.ConsistentHash; +import com.zfoo.net.util.ConsistentHash; import org.springframework.lang.Nullable; import java.util.TreeMap; diff --git a/util/src/main/java/com/zfoo/util/math/ConsistentHash.java b/net/src/main/java/com/zfoo/net/util/ConsistentHash.java similarity index 98% rename from util/src/main/java/com/zfoo/util/math/ConsistentHash.java rename to net/src/main/java/com/zfoo/net/util/ConsistentHash.java index 9e2818d1..e96af8b0 100644 --- a/util/src/main/java/com/zfoo/util/math/ConsistentHash.java +++ b/net/src/main/java/com/zfoo/net/util/ConsistentHash.java @@ -1,6 +1,5 @@ /* * Copyright (C) 2020 The zfoo Authors - * * 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 * @@ -11,7 +10,7 @@ * See the License for the specific language governing permissions and limitations under the License. */ -package com.zfoo.util.math; +package com.zfoo.net.util; import com.zfoo.protocol.model.Pair; diff --git a/util/src/main/java/com/zfoo/util/math/HashUtils.java b/net/src/main/java/com/zfoo/net/util/HashUtils.java similarity index 98% rename from util/src/main/java/com/zfoo/util/math/HashUtils.java rename to net/src/main/java/com/zfoo/net/util/HashUtils.java index 8956ff81..c6baf43b 100644 --- a/util/src/main/java/com/zfoo/util/math/HashUtils.java +++ b/net/src/main/java/com/zfoo/net/util/HashUtils.java @@ -1,6 +1,5 @@ /* * Copyright (C) 2020 The zfoo Authors - * * 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 * @@ -11,7 +10,7 @@ * See the License for the specific language governing permissions and limitations under the License. */ -package com.zfoo.util.math; +package com.zfoo.net.util; /** * 改进的hash算法虽然发布比较均匀,但是没有Java自带的hash算法速度快,所以需要知道自己需要什么 diff --git a/util/src/test/java/com/zfoo/util/math/ConsistentHashTest.java b/net/src/test/java/com/zfoo/net/util/ConsistentHashTest.java similarity index 99% rename from util/src/test/java/com/zfoo/util/math/ConsistentHashTest.java rename to net/src/test/java/com/zfoo/net/util/ConsistentHashTest.java index ccfad7ad..6b8069fb 100644 --- a/util/src/test/java/com/zfoo/util/math/ConsistentHashTest.java +++ b/net/src/test/java/com/zfoo/net/util/ConsistentHashTest.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and limitations under the License. */ -package com.zfoo.util.math; +package com.zfoo.net.util; import com.zfoo.protocol.model.Pair; import com.zfoo.protocol.util.JsonUtils; diff --git a/util/src/main/java/com/zfoo/util/math/Combinatorics.java b/util/src/main/java/com/zfoo/util/math/Combinatorics.java deleted file mode 100644 index 7bea7179..00000000 --- a/util/src/main/java/com/zfoo/util/math/Combinatorics.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2020 The zfoo Authors - * - * 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 com.zfoo.util.math; - -/** - * @author godotg - * @version 3.0 - */ -public class Combinatorics {// |kɒmbinəˋtɒ:riks|n.组合学 - - - //输出数组a的startIndex~endIndex(包括端点)的全排列 - public void permutation(int[] a, int startIndex, int endIndex) { - - if (startIndex == endIndex) { - for (int i = 0; i <= endIndex; i++) { - System.out.print(a[i]); - } - System.out.println(); - } - for (int i = startIndex; i <= endIndex; i++) { - swap(a, i, startIndex); - permutation(a, startIndex + 1, endIndex); - swap(a, i, startIndex); - } - } - - //输出数组a的全排列 - public void permutation(int[] a) { - permutation(a, 0, a.length - 1); - } - - - //public void Combination(int[] a,int[] b,int) - - //交换数组中的两个元素 - public void swap(int[] a, int xIndex, int yIndex) { - int temp = a[xIndex]; - a[xIndex] = a[yIndex]; - a[yIndex] = temp; - } - - -} diff --git a/util/src/test/java/com/zfoo/util/math/dfa/WordTreeTest.java b/util/src/test/java/com/zfoo/util/math/dfa/WordTreeTest.java deleted file mode 100644 index f683bd91..00000000 --- a/util/src/test/java/com/zfoo/util/math/dfa/WordTreeTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2020 The zfoo Authors - * - * 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 com.zfoo.util.math.dfa; - -import org.junit.Ignore; -import org.junit.Test; - -import java.util.List; - -/** - * @author godotg - * @version 3.0 - */ -@Ignore -public class WordTreeTest { - - @Test - public void test() { - WordTree tree = new WordTree(); - tree.addWord("大"); - tree.addWord("大土豆"); - tree.addWord("土豆"); - tree.addWord("刚出锅"); - tree.addWord("出锅"); - tree.addWord("fuck"); - - // 正文 - String text = "text asdff asdf afucksdf "; - List matchAll = tree.matchAll(text, -1, true, false); - System.out.println(matchAll); - } - -}