生活随笔
收集整理的這篇文章主要介紹了
架构设计分布式数据结构与算法面试题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
目錄
- 架構(gòu)設(shè)計(jì)
- 請(qǐng)列舉出在JDK中幾個(gè)常用的設(shè)計(jì)模式?
- 什么是設(shè)計(jì)模式?你是否在你的代碼里面使用過任何設(shè)計(jì)模式?
- 靜態(tài)代理、JDK動(dòng)態(tài)代理以及CGLIB動(dòng)態(tài)代理
- 靜態(tài)代理
- 動(dòng)態(tài)代理
- cglib代理
- 單例模式
- 工廠模式
- 觀察者模式
- 裝飾器模式
- 秒殺系統(tǒng)設(shè)計(jì)
- 分布式
- 分布式概述
- 分布式系統(tǒng)設(shè)計(jì)理念
- 分布式系統(tǒng)的目標(biāo)與要素
- 分布式系統(tǒng)設(shè)計(jì)兩大思路:中心化和去中心化
- 分布式與集群的區(qū)別是什么?
- CAP定理
- CAP定理的證明
- BASE理論
- BASE理論的核心思想
- BASE理論三要素
- 1. 基本可用
- 2. 軟狀態(tài)
- 3. 最終一致性
- 數(shù)據(jù)結(jié)構(gòu)與算法
- 冒泡排序(最高位確認(rèn)最大)
- 選擇排序(最低位選最小)
- 快速排序
- 遞歸
- 二分查找
- 一致性Hash算法
架構(gòu)設(shè)計(jì)
請(qǐng)列舉出在JDK中幾個(gè)常用的設(shè)計(jì)模式?
什么是設(shè)計(jì)模式?你是否在你的代碼里面使用過任何設(shè)計(jì)模式?
靜態(tài)代理、JDK動(dòng)態(tài)代理以及CGLIB動(dòng)態(tài)代理
靜態(tài)代理
動(dòng)態(tài)代理
cglib代理
單例模式
工廠模式
觀察者模式
裝飾器模式
秒殺系統(tǒng)設(shè)計(jì)
分布式
分布式概述
分布式
集群
微服務(wù)
多線程
高并發(fā)
分布式系統(tǒng)設(shè)計(jì)理念
分布式系統(tǒng)的目標(biāo)與要素
分布式系統(tǒng)設(shè)計(jì)兩大思路:中心化和去中心化
分布式與集群的區(qū)別是什么?
CAP定理
CAP定理的證明
BASE理論
BASE理論的核心思想
BASE理論三要素
1. 基本可用
2. 軟狀態(tài)
3. 最終一致性
數(shù)據(jù)結(jié)構(gòu)與算法
冒泡排序(最高位確認(rèn)最大)
選擇排序(最低位選最小)
快速排序
遞歸
二分查找
一致性Hash算法
概述
一致性Hash算法原理
Java代碼實(shí)現(xiàn)
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
);}}
轉(zhuǎn)載鏈接:https://blog.csdn.net/ThinkWon/article/details/105870730
總結(jié)
以上是生活随笔為你收集整理的架构设计分布式数据结构与算法面试题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。