Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
system-design-primer
Commits
f099a0ad
Commit
f099a0ad
authored
Mar 07, 2018
by
cclauss
Committed by
Donne Martin
Mar 06, 2018
Browse files
Convert all .py files to be valid Python (#98)
parent
3ca1f1d0
Changes
7
Show whitespace changes
Inline
Side-by-side
solutions/object_oriented_design/call_center/call_center.py
View file @
f099a0ad
...
@@ -112,6 +112,11 @@ class CallCenter(object):
...
@@ -112,6 +112,11 @@ class CallCenter(object):
return
employee
return
employee
return
None
return
None
def
notify_call_escalated
(
self
,
call
):
# ...
def
notify_call_escalated
(
self
,
call
):
def
notify_call_completed
(
self
,
call
):
# ...
pass
def
dispatch_queued_call_to_newly_freed_employee
(
self
,
call
,
employee
):
# ...
\ No newline at end of file
def
notify_call_completed
(
self
,
call
):
pass
def
dispatch_queued_call_to_newly_freed_employee
(
self
,
call
,
employee
):
pass
solutions/object_oriented_design/deck_of_cards/deck_of_cards.py
View file @
f099a0ad
...
@@ -92,7 +92,7 @@ class BlackJackHand(Hand):
...
@@ -92,7 +92,7 @@ class BlackJackHand(Hand):
def
possible_scores
(
self
):
def
possible_scores
(
self
):
"""Return a list of possible scores, taking Aces into account."""
"""Return a list of possible scores, taking Aces into account."""
# ...
pass
class
Deck
(
object
):
class
Deck
(
object
):
...
@@ -113,4 +113,5 @@ class Deck(object):
...
@@ -113,4 +113,5 @@ class Deck(object):
return
None
return
None
return
card
return
card
def
shuffle
(
self
):
# ...
def
shuffle
(
self
):
\ No newline at end of file
pass
solutions/object_oriented_design/lru_cache/lru_cache.py
View file @
f099a0ad
...
@@ -11,9 +11,14 @@ class LinkedList(object):
...
@@ -11,9 +11,14 @@ class LinkedList(object):
self
.
head
=
None
self
.
head
=
None
self
.
tail
=
None
self
.
tail
=
None
def
move_to_front
(
self
,
node
):
# ...
def
move_to_front
(
self
,
node
):
def
append_to_front
(
self
,
node
):
# ...
pass
def
remove_from_tail
(
self
):
# ...
def
append_to_front
(
self
,
node
):
pass
def
remove_from_tail
(
self
):
pass
class
Cache
(
object
):
class
Cache
(
object
):
...
...
solutions/object_oriented_design/online_chat/online_chat.py
View file @
f099a0ad
...
@@ -6,11 +6,20 @@ class UserService(object):
...
@@ -6,11 +6,20 @@ class UserService(object):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
users_by_id
=
{}
# key: user id, value: User
self
.
users_by_id
=
{}
# key: user id, value: User
def
add_user
(
self
,
user_id
,
name
,
pass_hash
):
# ...
def
add_user
(
self
,
user_id
,
name
,
pass_hash
):
def
remove_user
(
self
,
user_id
):
# ...
pass
def
add_friend_request
(
self
,
from_user_id
,
to_user_id
):
# ...
def
approve_friend_request
(
self
,
from_user_id
,
to_user_id
):
# ...
def
remove_user
(
self
,
user_id
):
def
reject_friend_request
(
self
,
from_user_id
,
to_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
):
class
User
(
object
):
...
@@ -25,12 +34,23 @@ class User(object):
...
@@ -25,12 +34,23 @@ class User(object):
self
.
received_friend_requests_by_friend_id
=
{}
# key: friend id, value: AddRequest
self
.
received_friend_requests_by_friend_id
=
{}
# key: friend id, value: AddRequest
self
.
sent_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_user
(
self
,
friend_id
,
message
):
def
message_group
(
self
,
group_id
,
message
):
# ...
pass
def
send_friend_request
(
self
,
friend_id
):
# ...
def
receive_friend_request
(
self
,
friend_id
):
# ...
def
message_group
(
self
,
group_id
,
message
):
def
approve_friend_request
(
self
,
friend_id
):
# ...
pass
def
reject_friend_request
(
self
,
friend_id
):
# ...
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
):
class
Chat
(
metaclass
=
ABCMeta
):
...
@@ -51,8 +71,11 @@ class PrivateChat(Chat):
...
@@ -51,8 +71,11 @@ class PrivateChat(Chat):
class
GroupChat
(
Chat
):
class
GroupChat
(
Chat
):
def
add_user
(
self
,
user
):
# ...
def
add_user
(
self
,
user
):
def
remove_user
(
self
,
user
):
# ...
pass
def
remove_user
(
self
,
user
):
pass
class
Message
(
object
):
class
Message
(
object
):
...
...
solutions/object_oriented_design/parking_lot/parking_lot.py
View file @
f099a0ad
from
abc
import
ABCMeta
,
abstractmethod
from
abc
import
ABCMeta
,
abstractmethod
from
enum
import
Enum
class
VehicleSize
(
Enum
):
class
VehicleSize
(
Enum
):
...
@@ -92,11 +93,11 @@ class Level(object):
...
@@ -92,11 +93,11 @@ class Level(object):
def
_find_available_spot
(
self
,
vehicle
):
def
_find_available_spot
(
self
,
vehicle
):
"""Find an available spot where vehicle can fit, or return None"""
"""Find an available spot where vehicle can fit, or return None"""
# ...
pass
def
_park_starting_at_spot
(
self
,
spot
,
vehicle
):
def
_park_starting_at_spot
(
self
,
spot
,
vehicle
):
"""Occupy starting at spot.spot_number to vehicle.spot_size."""
"""Occupy starting at spot.spot_number to vehicle.spot_size."""
# ...
pass
class
ParkingSpot
(
object
):
class
ParkingSpot
(
object
):
...
@@ -117,5 +118,8 @@ class ParkingSpot(object):
...
@@ -117,5 +118,8 @@ class ParkingSpot(object):
return
False
return
False
return
vehicle
.
can_fit_in_spot
(
self
)
return
vehicle
.
can_fit_in_spot
(
self
)
def
park_vehicle
(
self
,
vehicle
):
# ...
def
park_vehicle
(
self
,
vehicle
):
def
remove_vehicle
(
self
):
# ...
pass
\ No newline at end of file
def
remove_vehicle
(
self
):
pass
solutions/system_design/social_graph/social_graph_snippets.py
View file @
f099a0ad
...
@@ -61,3 +61,4 @@ class UserGraphService(object):
...
@@ -61,3 +61,4 @@ class UserGraphService(object):
def
bfs
(
self
,
source
,
dest
):
def
bfs
(
self
,
source
,
dest
):
# Use self.visited_ids to track visited nodes
# Use self.visited_ids to track visited nodes
# Use self.lookup to translate a person_id to a Person
# Use self.lookup to translate a person_id to a Person
pass
solutions/system_design/web_crawler/web_crawler_snippets.py
View file @
f099a0ad
...
@@ -2,33 +2,33 @@
...
@@ -2,33 +2,33 @@
class
PagesDataStore
(
object
):
class
PagesDataStore
(
object
):
def
__init__
(
self
,
db
)
;
def
__init__
(
self
,
db
)
:
self
.
db
=
db
self
.
db
=
db
...
pass
def
add_link_to_crawl
(
self
,
url
):
def
add_link_to_crawl
(
self
,
url
):
"""Add the given link to `links_to_crawl`."""
"""Add the given link to `links_to_crawl`."""
...
pass
def
remove_link_to_crawl
(
self
,
url
):
def
remove_link_to_crawl
(
self
,
url
):
"""Remove the given link from `links_to_crawl`."""
"""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."""
"""Reduce the priority of a link in `links_to_crawl` to avoid cycles."""
...
pass
def
extract_max_priority_page
(
self
):
def
extract_max_priority_page
(
self
):
"""Return the highest priority link in `links_to_crawl`."""
"""Return the highest priority link in `links_to_crawl`."""
...
pass
def
insert_crawled_link
(
self
,
url
,
signature
):
def
insert_crawled_link
(
self
,
url
,
signature
):
"""Add the given link to `crawled_links`."""
"""Add the given link to `crawled_links`."""
...
pass
def
crawled_similar
(
self
,
signature
):
def
crawled_similar
(
self
,
signature
):
"""Determine if we've already crawled a page matching the given signature"""
"""Determine if we've already crawled a page matching the given signature"""
...
pass
class
Page
(
object
):
class
Page
(
object
):
...
@@ -41,7 +41,7 @@ class Page(object):
...
@@ -41,7 +41,7 @@ class Page(object):
def
create_signature
(
self
):
def
create_signature
(
self
):
# Create signature based on url and contents
# Create signature based on url and contents
...
pass
class
Crawler
(
object
):
class
Crawler
(
object
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment