From 3ca1f1d0d2f3b7e1bb76209ed129969f281463e2 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Mon, 5 Mar 2018 20:29:07 -0500 Subject: [PATCH 1/7] Add Greek translation link (#140) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce25eb53..33451322 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [Brazilian Portuguese](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Italian](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [Korean](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [Persian](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polish](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [Russian](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Turkish](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [Vietnamese](https://github.com/donnemartin/system-design-primer/issues/127) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)* +*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [Brazilian Portuguese](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Greek](https://github.com/donnemartin/system-design-primer/issues/130) ∙ [Italian](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [Korean](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [Persian](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polish](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [Russian](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Turkish](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [Vietnamese](https://github.com/donnemartin/system-design-primer/issues/127) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)* # The System Design Primer From f099a0ad3f3e6ac16727bc29e77d1e3ac8d40e22 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 7 Mar 2018 01:37:46 +0100 Subject: [PATCH 2/7] Convert all .py files to be valid Python (#98) --- .../call_center/call_center.py | 11 ++-- .../deck_of_cards/deck_of_cards.py | 5 +- .../lru_cache/lru_cache.py | 17 ++++--- .../online_chat/online_chat.py | 51 ++++++++++++++----- .../parking_lot/parking_lot.py | 12 +++-- .../social_graph/social_graph_snippets.py | 1 + .../web_crawler/web_crawler_snippets.py | 20 ++++---- 7 files changed, 78 insertions(+), 39 deletions(-) diff --git a/solutions/object_oriented_design/call_center/call_center.py b/solutions/object_oriented_design/call_center/call_center.py index 7bdd992b..a2785594 100644 --- a/solutions/object_oriented_design/call_center/call_center.py +++ b/solutions/object_oriented_design/call_center/call_center.py @@ -112,6 +112,11 @@ class CallCenter(object): return employee return None - def notify_call_escalated(self, call): # ... - def notify_call_completed(self, call): # ... - def dispatch_queued_call_to_newly_freed_employee(self, call, employee): # ... \ No newline at end of file + def notify_call_escalated(self, call): + pass + + def notify_call_completed(self, call): + pass + + def dispatch_queued_call_to_newly_freed_employee(self, call, employee): + pass diff --git a/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py b/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py index 2ec4f1bc..8dc56548 100644 --- a/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py +++ b/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py @@ -92,7 +92,7 @@ class BlackJackHand(Hand): def possible_scores(self): """Return a list of possible scores, taking Aces into account.""" - # ... + pass class Deck(object): @@ -113,4 +113,5 @@ class Deck(object): return None return card - def shuffle(self): # ... \ No newline at end of file + def shuffle(self): + pass diff --git a/solutions/object_oriented_design/lru_cache/lru_cache.py b/solutions/object_oriented_design/lru_cache/lru_cache.py index 3652aeb6..c2c38faa 100644 --- a/solutions/object_oriented_design/lru_cache/lru_cache.py +++ b/solutions/object_oriented_design/lru_cache/lru_cache.py @@ -11,9 +11,14 @@ class LinkedList(object): self.head = None self.tail = None - def move_to_front(self, node): # ... - def append_to_front(self, node): # ... - def remove_from_tail(self): # ... + def move_to_front(self, node): + pass + + def append_to_front(self, node): + pass + + def remove_from_tail(self): + pass class Cache(object): @@ -26,7 +31,7 @@ class Cache(object): def get(self, query) """Get the stored query result from the cache. - + Accessing a node updates its position to the front of the LRU list. """ node = self.lookup[query] @@ -37,7 +42,7 @@ class Cache(object): def set(self, results, query): """Set the result for the given query key in the cache. - + When updating an entry, updates its position to the front of the LRU list. If the entry is new and the cache is at capacity, removes the oldest entry before the new entry is added. @@ -58,4 +63,4 @@ class Cache(object): # Add the new key and value new_node = Node(results) self.linked_list.append_to_front(new_node) - self.lookup[query] = new_node \ No newline at end of file + self.lookup[query] = new_node diff --git a/solutions/object_oriented_design/online_chat/online_chat.py b/solutions/object_oriented_design/online_chat/online_chat.py index d7426295..c9e5a984 100644 --- a/solutions/object_oriented_design/online_chat/online_chat.py +++ b/solutions/object_oriented_design/online_chat/online_chat.py @@ -6,11 +6,20 @@ class UserService(object): def __init__(self): self.users_by_id = {} # key: user id, value: User - def add_user(self, user_id, name, pass_hash): # ... - def remove_user(self, user_id): # ... - def add_friend_request(self, from_user_id, to_user_id): # ... - def approve_friend_request(self, from_user_id, to_user_id): # ... - def reject_friend_request(self, from_user_id, to_user_id): # ... + def add_user(self, user_id, name, pass_hash): + pass + + def remove_user(self, user_id): + pass + + def add_friend_request(self, from_user_id, to_user_id): + pass + + def approve_friend_request(self, from_user_id, to_user_id): + pass + + def reject_friend_request(self, from_user_id, to_user_id): + pass class User(object): @@ -25,12 +34,23 @@ class User(object): self.received_friend_requests_by_friend_id = {} # key: friend id, value: AddRequest self.sent_friend_requests_by_friend_id = {} # key: friend id, value: AddRequest - def message_user(self, friend_id, message): # ... - def message_group(self, group_id, message): # ... - def send_friend_request(self, friend_id): # ... - def receive_friend_request(self, friend_id): # ... - def approve_friend_request(self, friend_id): # ... - def reject_friend_request(self, friend_id): # ... + def message_user(self, friend_id, message): + pass + + def message_group(self, group_id, message): + pass + + def send_friend_request(self, friend_id): + pass + + def receive_friend_request(self, friend_id): + pass + + def approve_friend_request(self, friend_id): + pass + + def reject_friend_request(self, friend_id): + pass class Chat(metaclass=ABCMeta): @@ -51,8 +71,11 @@ class PrivateChat(Chat): class GroupChat(Chat): - def add_user(self, user): # ... - def remove_user(self, user): # ... + def add_user(self, user): + pass + + def remove_user(self, user): + pass class Message(object): @@ -77,4 +100,4 @@ class RequestStatus(Enum): UNREAD = 0 READ = 1 ACCEPTED = 2 - REJECTED = 3 \ No newline at end of file + REJECTED = 3 diff --git a/solutions/object_oriented_design/parking_lot/parking_lot.py b/solutions/object_oriented_design/parking_lot/parking_lot.py index c34c010b..9167d9fd 100644 --- a/solutions/object_oriented_design/parking_lot/parking_lot.py +++ b/solutions/object_oriented_design/parking_lot/parking_lot.py @@ -1,4 +1,5 @@ from abc import ABCMeta, abstractmethod +from enum import Enum class VehicleSize(Enum): @@ -92,11 +93,11 @@ class Level(object): def _find_available_spot(self, vehicle): """Find an available spot where vehicle can fit, or return None""" - # ... + pass def _park_starting_at_spot(self, spot, vehicle): """Occupy starting at spot.spot_number to vehicle.spot_size.""" - # ... + pass class ParkingSpot(object): @@ -117,5 +118,8 @@ class ParkingSpot(object): return False return vehicle.can_fit_in_spot(self) - def park_vehicle(self, vehicle): # ... - def remove_vehicle(self): # ... \ No newline at end of file + def park_vehicle(self, vehicle): + pass + + def remove_vehicle(self): + pass diff --git a/solutions/system_design/social_graph/social_graph_snippets.py b/solutions/system_design/social_graph/social_graph_snippets.py index 32941111..f1cc6963 100644 --- a/solutions/system_design/social_graph/social_graph_snippets.py +++ b/solutions/system_design/social_graph/social_graph_snippets.py @@ -61,3 +61,4 @@ class UserGraphService(object): def bfs(self, source, dest): # Use self.visited_ids to track visited nodes # Use self.lookup to translate a person_id to a Person + pass diff --git a/solutions/system_design/web_crawler/web_crawler_snippets.py b/solutions/system_design/web_crawler/web_crawler_snippets.py index e85e2361..99d5a378 100644 --- a/solutions/system_design/web_crawler/web_crawler_snippets.py +++ b/solutions/system_design/web_crawler/web_crawler_snippets.py @@ -2,33 +2,33 @@ class PagesDataStore(object): - def __init__(self, db); + def __init__(self, db): self.db = db - ... + pass def add_link_to_crawl(self, url): """Add the given link to `links_to_crawl`.""" - ... + pass def remove_link_to_crawl(self, url): """Remove the given link from `links_to_crawl`.""" - ... + pass - def reduce_priority_link_to_crawl(self, url) + def reduce_priority_link_to_crawl(self, url): """Reduce the priority of a link in `links_to_crawl` to avoid cycles.""" - ... + pass def extract_max_priority_page(self): """Return the highest priority link in `links_to_crawl`.""" - ... + pass def insert_crawled_link(self, url, signature): """Add the given link to `crawled_links`.""" - ... + pass def crawled_similar(self, signature): """Determine if we've already crawled a page matching the given signature""" - ... + pass class Page(object): @@ -41,7 +41,7 @@ class Page(object): def create_signature(self): # Create signature based on url and contents - ... + pass class Crawler(object): From e53b20b5e5a912d2c3cc65a92962fd050312fdd0 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 8 Mar 2018 09:37:45 +0800 Subject: [PATCH 3/7] zh-Hans: Fix typos (#141) --- README-zh-Hans.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README-zh-Hans.md b/README-zh-Hans.md index c681366d..b16cc03b 100644 --- a/README-zh-Hans.md +++ b/README-zh-Hans.md @@ -98,7 +98,7 @@ > 各种系统设计主题的摘要,包括优点和缺点。**每一个主题都面临着取舍和权衡**。 > -> 每个章节都包含着更的资源的链接。 +> 每个章节都包含着更多的资源的链接。

@@ -108,7 +108,7 @@ * [系统设计主题:从这里开始](#系统设计主题从这里开始) * [第一步:回顾可扩展性的视频讲座](#第一步回顾可扩展性scalability的视频讲座) - * [第二步: 回顾可扩展性的文章](#第二步回顾可扩展性文章) + * [第二步:回顾可扩展性的文章](#第二步回顾可扩展性文章) * [接下来的步骤](#接下来的步骤) * [性能与拓展性](#性能与可扩展性) * [延迟与吞吐量](#延迟与吞吐量) @@ -207,7 +207,7 @@ 那些有经验的候选人通常会被期望了解更多的系统设计的知识。架构师或者团队负责人则会被期望了解更多除了个人贡献之外的知识。顶级的科技公司通常也会有一次或者更多的系统设计面试。 -面试会很宽泛的展开并在几个领域深入。这回帮助你了解一些关于系统设计的不同的主题。基于你的时间线,经验,面试的职位和面试的公司对下面的指导做出适当的调整。 +面试会很宽泛的展开并在几个领域深入。这会帮助你了解一些关于系统设计的不同的主题。基于你的时间线,经验,面试的职位和面试的公司对下面的指导做出适当的调整。 * **短期** - 以系统设计主题的**广度**为目标。通过解决**一些**面试题来练习。 * **中期** - 以系统设计主题的**广度**和**初级深度**为目标。通过解决**很多**面试题来练习。 @@ -242,9 +242,9 @@ * 我们希望每秒钟处理多少请求? * 我们希望的读写比率? -### 第二步:创造一个高级的设计 +### 第二步:创造一个高层级的设计 -使用所有重要的组件来描绘出一个高级的设计。 +使用所有重要的组件来描绘出一个高层级的设计。 * 画出主要的组件和连接 * 证明你的想法 @@ -273,11 +273,11 @@ 论述可能的解决办法和代价。每件事情需要取舍。可以使用[可拓展系统的设计原则](#系统设计主题的索引)来处理瓶颈。 -### 信封背面的计算 +### 预估计算量 你或许会被要求通过手算进行一些估算。涉及到的[附录](#附录)涉及到的是下面的这些资源: -* [使用信封的背面做计算](http://highscalability.com/blog/2011/1/26/google-pro-tip-use-back-of-the-envelope-calculations-to-choo.html) +* [使用预估计算量](http://highscalability.com/blog/2011/1/26/google-pro-tip-use-back-of-the-envelope-calculations-to-choo.html) * [2 的次方表](#2-的次方表) * [每个程序员都应该知道的延迟数](#每个程序员都应该知道的延迟数) From 38a93dc190092d20a95f7485fbe1d3735a53d716 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Wed, 7 Mar 2018 20:38:49 -0500 Subject: [PATCH 4/7] Add Spanish translation link (#142) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33451322..1b4673bb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [Brazilian Portuguese](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Greek](https://github.com/donnemartin/system-design-primer/issues/130) ∙ [Italian](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [Korean](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [Persian](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polish](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [Russian](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Turkish](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [Vietnamese](https://github.com/donnemartin/system-design-primer/issues/127) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)* +*[English](README.md) ∙ [日本語](README-ja.md) ∙ [简体中文](README-zh-Hans.md) ∙ [繁體中文](README-zh-TW.md) | [Brazilian Portuguese](https://github.com/donnemartin/system-design-primer/issues/40) ∙ [Greek](https://github.com/donnemartin/system-design-primer/issues/130) ∙ [Italian](https://github.com/donnemartin/system-design-primer/issues/104) ∙ [Korean](https://github.com/donnemartin/system-design-primer/issues/102) ∙ [Persian](https://github.com/donnemartin/system-design-primer/issues/110) ∙ [Polish](https://github.com/donnemartin/system-design-primer/issues/68) ∙ [Russian](https://github.com/donnemartin/system-design-primer/issues/87) ∙ [Spanish](https://github.com/donnemartin/system-design-primer/issues/136) ∙ [Turkish](https://github.com/donnemartin/system-design-primer/issues/39) ∙ [Vietnamese](https://github.com/donnemartin/system-design-primer/issues/127) | [Add Translation](https://github.com/donnemartin/system-design-primer/issues/28)* # The System Design Primer From 0178943013f08cfc2a5c083e5d39be70ba72bbdc Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 18 Mar 2018 14:19:08 +0100 Subject: [PATCH 5/7] Add missing colons to class methods (#143) --- solutions/object_oriented_design/lru_cache/lru_cache.py | 2 +- solutions/system_design/query_cache/query_cache_snippets.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/object_oriented_design/lru_cache/lru_cache.py b/solutions/object_oriented_design/lru_cache/lru_cache.py index c2c38faa..75fe44d4 100644 --- a/solutions/object_oriented_design/lru_cache/lru_cache.py +++ b/solutions/object_oriented_design/lru_cache/lru_cache.py @@ -29,7 +29,7 @@ class Cache(object): self.lookup = {} # key: query, value: node self.linked_list = LinkedList() - def get(self, query) + def get(self, query): """Get the stored query result from the cache. Accessing a node updates its position to the front of the LRU list. diff --git a/solutions/system_design/query_cache/query_cache_snippets.py b/solutions/system_design/query_cache/query_cache_snippets.py index 469dc7c6..6ea3bac0 100644 --- a/solutions/system_design/query_cache/query_cache_snippets.py +++ b/solutions/system_design/query_cache/query_cache_snippets.py @@ -52,7 +52,7 @@ class Cache(object): self.lookup = {} self.linked_list = LinkedList() - def get(self, query) + def get(self, query): """Get the stored query result from the cache. Accessing a node updates its position to the front of the LRU list. From b156e48e4b1f515694f16bd29293ed6c28b8ad18 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 18 Mar 2018 14:21:52 +0100 Subject: [PATCH 6/7] Add missing self variables to Deck of Cards solution (#145) --- .../object_oriented_design/deck_of_cards/deck_of_cards.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py b/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py index 8dc56548..a4708758 100644 --- a/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py +++ b/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py @@ -68,7 +68,7 @@ class Hand(object): def score(self): total_value = 0 - for card in card: + for card in self.cards: total_value += card.value return total_value @@ -102,9 +102,9 @@ class Deck(object): self.deal_index = 0 def remaining_cards(self): - return len(self.cards) - deal_index + return len(self.cards) - self.deal_index - def deal_card(): + def deal_card(self): try: card = self.cards[self.deal_index] card.is_available = False From ea262de564f8ab749e47960764a63a4cd7d48df4 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 25 Mar 2018 00:38:34 +0100 Subject: [PATCH 7/7] Add deque import to Social Graph solution (#147) --- solutions/system_design/social_graph/social_graph_snippets.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/system_design/social_graph/social_graph_snippets.py b/solutions/system_design/social_graph/social_graph_snippets.py index f1cc6963..8a83f748 100644 --- a/solutions/system_design/social_graph/social_graph_snippets.py +++ b/solutions/system_design/social_graph/social_graph_snippets.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from collections import deque + class Graph(object):