正在显示
4 个修改的文件
包含
23 行增加
和
5 行删除
| @@ -3,7 +3,7 @@ package com.crossoverjie.cim.common.route.algorithm.consistenthash; | @@ -3,7 +3,7 @@ package com.crossoverjie.cim.common.route.algorithm.consistenthash; | ||
| 3 | import com.crossoverjie.cim.common.data.construct.SortArrayMap; | 3 | import com.crossoverjie.cim.common.data.construct.SortArrayMap; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | - * Function: | 6 | + * Function:自定义排序 Map 实现 |
| 7 | * | 7 | * |
| 8 | * @author crossoverJie | 8 | * @author crossoverJie |
| 9 | * Date: 2019-02-27 00:38 | 9 | * Date: 2019-02-27 00:38 |
| @@ -21,7 +21,6 @@ public class SortArrayMapConsistentHash extends AbstractConsistentHash { | @@ -21,7 +21,6 @@ public class SortArrayMapConsistentHash extends AbstractConsistentHash { | ||
| 21 | @Override | 21 | @Override |
| 22 | public void sort() { | 22 | public void sort() { |
| 23 | sortArrayMap.sort(); | 23 | sortArrayMap.sort(); |
| 24 | - sortArrayMap.print(); | ||
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | @Override | 26 | @Override |
| @@ -4,7 +4,7 @@ import java.util.SortedMap; | @@ -4,7 +4,7 @@ import java.util.SortedMap; | ||
| 4 | import java.util.TreeMap; | 4 | import java.util.TreeMap; |
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| 7 | - * Function: | 7 | + * Function:TreeMap 实现 |
| 8 | * | 8 | * |
| 9 | * @author crossoverJie | 9 | * @author crossoverJie |
| 10 | * Date: 2019-02-27 01:16 | 10 | * Date: 2019-02-27 01:16 |
| @@ -2,6 +2,8 @@ package com.crossoverjie.cim.common.data.construct; | @@ -2,6 +2,8 @@ package com.crossoverjie.cim.common.data.construct; | ||
| 2 | 2 | ||
| 3 | import org.junit.Test; | 3 | import org.junit.Test; |
| 4 | 4 | ||
| 5 | +import java.util.TreeMap; | ||
| 6 | + | ||
| 5 | public class SortArrayMapTest { | 7 | public class SortArrayMapTest { |
| 6 | 8 | ||
| 7 | @Test | 9 | @Test |
| @@ -154,4 +156,18 @@ public class SortArrayMapTest { | @@ -154,4 +156,18 @@ public class SortArrayMapTest { | ||
| 154 | System.out.println("不排耗时 " + (end -star)); | 156 | System.out.println("不排耗时 " + (end -star)); |
| 155 | System.out.println(map.size()); | 157 | System.out.println(map.size()); |
| 156 | } | 158 | } |
| 159 | + @Test | ||
| 160 | + public void add7(){ | ||
| 161 | + | ||
| 162 | + TreeMap<Long,String> treeMap = new TreeMap<Long, String>() ; | ||
| 163 | + long star = System.currentTimeMillis() ; | ||
| 164 | + for (int i = 0; i < count; i++) { | ||
| 165 | + double d = Math.random(); | ||
| 166 | + int ran = (int)(d*100); | ||
| 167 | + treeMap.put(Long.valueOf(i + ran) ,"127.0.0." + i); | ||
| 168 | + } | ||
| 169 | + long end = System.currentTimeMillis() ; | ||
| 170 | + System.out.println("耗时 " + (end -star)); | ||
| 171 | + System.out.println(treeMap.size()); | ||
| 172 | + } | ||
| 157 | } | 173 | } |
| @@ -27,8 +27,11 @@ app.zk.root=/route | @@ -27,8 +27,11 @@ app.zk.root=/route | ||
| 27 | #路由策略,一致性 hash | 27 | #路由策略,一致性 hash |
| 28 | app.route.way=com.crossoverjie.cim.common.route.algorithm.consistenthash.ConsistentHashHandle | 28 | app.route.way=com.crossoverjie.cim.common.route.algorithm.consistenthash.ConsistentHashHandle |
| 29 | 29 | ||
| 30 | -#一致性 hash 算法具体实现 | ||
| 31 | -app.route.way.consitenthash=com.crossoverjie.cim.common.route.algorithm.consistenthash.SortArrayMapConsistentHash | 30 | +#一致性 hash 算法具体实现--自定义有序 map |
| 31 | +#app.route.way.consitenthash=com.crossoverjie.cim.common.route.algorithm.consistenthash.SortArrayMapConsistentHash | ||
| 32 | + | ||
| 33 | +#一致性 hash 算法具体实现--TreeMap | ||
| 34 | +app.route.way.consitenthash=com.crossoverjie.cim.common.route.algorithm.consistenthash.TreeMapConsistentHash | ||
| 32 | 35 | ||
| 33 | # Redis 配置 | 36 | # Redis 配置 |
| 34 | spring.redis.host=47.98.194.60 | 37 | spring.redis.host=47.98.194.60 |
-
请 注册 或 登录 后发表评论