forked from HU-CS201-master/chap01
/
sset.py
103 lines (90 loc) · 2.25 KB
/
sset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
class SSet:
def __init__(self):
'''Initializes member variables.
>>> sset = SSet()
'''
pass
def __str__(self):
'''Returns a string representation of an object for printing.
>>> sset = SSet()
>>> print(sset) # prints sset.__str__()
'''
pass
def add(self, key, val):
'''Adds the pair (key, val) to the SSet if no pair with key
already exists in the SSet, and returns True. Returns False if a
pair with key already exists in the SSet.
>>> sset = SSet()
>>> sset.add(1, 10)
True
>>> sset.add(2, 20)
True
>>> sset.add(2, 30)
False
'''
pass
def remove(self, key):
'''Removes the pair with key from the SSet and returns it.
Returns None if no such pair exsits.
>>> sset = SSet()
>>> sset.add(1, 10)
True
>>> sset.add(2, 20)
True
>>> sset.remove(1)
(1, 10)
>>> sset.remove(10)
>>>
'''
pass
def find(self, key):
'''Returns the pair from the SSet that contains key. If no such
pair exists, returns the pair from the SSet that contains the
successor of key. Returns None if no such pair exists.
>>> sset = SSet()
>>> sset.add(1, 10)
True
>>> sset.add(2, 20)
True
>>> sset.find(1)
(1, 10)
>>> sset.find(1.5)
(2, 20)
>>> sset.find(3)
>>>
'''
pass
def size(self):
'''Returns the number of pairs currently in the SSet.
>>> sset = SSet()
>>> sset.size()
0
>>> sset.add(1, 10)
True
>>> sset.add(2, 20)
True
>>> sset.size()
2
>>> sset.add(2, 30)
False
>>> sset.size()
2
'''
pass
def keys(self):
'''Returns a list of keys in the SSet.
>>> sset = SSet()
>>> sset.keys()
[]
>>> sset.add(1, 10)
True
>>> sset.add(2, 20)
True
>>> sset.keys()
[1, 2]
>>> sset.add(2, 30)
False
>>> sset.keys()
[1, 2]
'''
pass