生活随笔
收集整理的這篇文章主要介紹了
架构设计分布式数据结构与算法面试题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 架構設計
- 請列舉出在JDK中幾個常用的設計模式?
- 什么是設計模式?你是否在你的代碼里面使用過任何設計模式?
- 靜態代理、JDK動態代理以及CGLIB動態代理
- 單例模式
- 工廠模式
- 觀察者模式
- 裝飾器模式
- 秒殺系統設計
- 分布式
- 分布式概述
- 分布式系統設計理念
- 分布式系統的目標與要素
- 分布式系統設計兩大思路:中心化和去中心化
- 分布式與集群的區別是什么?
- CAP定理
- CAP定理的證明
- BASE理論
- BASE理論的核心思想
- BASE理論三要素
- 數據結構與算法
- 冒泡排序(最高位確認最大)
- 選擇排序(最低位選最小)
- 快速排序
- 遞歸
- 二分查找
- 一致性Hash算法
架構設計
請列舉出在JDK中幾個常用的設計模式?
什么是設計模式?你是否在你的代碼里面使用過任何設計模式?
靜態代理、JDK動態代理以及CGLIB動態代理
靜態代理
動態代理
cglib代理
單例模式
工廠模式
觀察者模式
裝飾器模式
秒殺系統設計
分布式
分布式概述
分布式
集群
微服務
多線程
高并發
分布式系統設計理念
分布式系統的目標與要素
分布式系統設計兩大思路:中心化和去中心化
分布式與集群的區別是什么?
CAP定理
CAP定理的證明
BASE理論
BASE理論的核心思想
BASE理論三要素
1. 基本可用
2. 軟狀態
3. 最終一致性
數據結構與算法
冒泡排序(最高位確認最大)
選擇排序(最低位選最小)
快速排序
遞歸
二分查找
一致性Hash算法
概述
一致性Hash算法原理
Java代碼實現
public class ConsistentHash<T> {private final int numberOfReplicas
;private final SortedMap
<Integer, T> circle
= new TreeMap<Integer, T>();public ConsistentHash(int numberOfReplicas
, Collection
<T> nodes
) {this.numberOfReplicas
= numberOfReplicas
;for (T node
: nodes
) {add(node
);}}public void add(T node
) {for (int i
= 0; i
< numberOfReplicas
; i
++) {String nodestr
= node
.toString() + i
;int hashcode
= nodestr
.hashCode();System
.out
.println("hashcode:" + hashcode
);circle
.put(hashcode
, node
);}}public void remove(T node
) {for (int i
= 0; i
< numberOfReplicas
; i
++) {circle
.remove((node
.toString() + i
).hashCode());}}public T
get(Object key
) {if (circle
.isEmpty()) {return null
;}int hash
= key
.hashCode();System
.out
.println("hashcode----->:" + hash
);if (!circle
.containsKey(hash
)) {SortedMap
<Integer, T> tailMap
= circle
.tailMap(hash
);hash
= tailMap
.isEmpty() ? circle
.firstKey() : tailMap
.firstKey();}return circle
.get(hash
);}public long getSize() {return circle
.size();}public void testBalance() {Set
<Integer> sets
= circle
.keySet();SortedSet
<Integer> sortedSets
= new TreeSet<Integer>(sets
);for (Integer hashCode
: sortedSets
) {System
.out
.println(hashCode
);}System
.out
.println("----each location 's distance are follows: ----");Iterator
<Integer> it
= sortedSets
.iterator();Iterator
<Integer> it2
= sortedSets
.iterator();if (it2
.hasNext()) {it2
.next();}long keyPre
, keyAfter
;while (it
.hasNext() && it2
.hasNext()) {keyPre
= it
.next();keyAfter
= it2
.next();System
.out
.println(keyAfter
- keyPre
);}}public static void main(String
[] args
) {Set
<String> nodes
= new HashSet<String>();nodes
.add("A");nodes
.add("B");nodes
.add("C");ConsistentHash
<String> consistentHash
= new ConsistentHash<String>(2, nodes
);consistentHash
.add("D");System
.out
.println("hash circle size: " + consistentHash
.getSize());System
.out
.println("location of each node are follows: ");consistentHash
.testBalance();String node
= consistentHash
.get("apple");System
.out
.println("node----------->:" + node
);}}
轉載鏈接:https://blog.csdn.net/ThinkWon/article/details/105870730
總結
以上是生活随笔為你收集整理的架构设计分布式数据结构与算法面试题的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。