You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/lectures/data/dictionary.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,7 @@ Then, a dictionary has only two attributes: an array of `Cell`s, and a probe seq
88
88
!include`snippetStart="// - and a probe sequence strategy.", snippetEnd="// The ToString method uses String.Format"` code/projects/Dictionary/Dictionary/Dictionary.cs
89
89
```
90
90
91
-
The default size of 31 and the reason why we are using the `NextPrime` method are discussed [further down](#array-size).
91
+
The default size of 31 and the reason why we are using the `NextPrime` method are discussed [further down](#how-is-the-size-of-the-array-decided).
92
92
93
93
#### Computing the index
94
94
@@ -113,7 +113,7 @@ We obtain the following, where the details of `CollisionResolution` are not impo
113
113
Adding an element is a delicate process.
114
114
We only need a key and a value, and then we
115
115
116
-
- make sure the dictionary does not already contain a key-value pair with the same key ([detailed below](#find)),
116
+
- make sure the dictionary does not already contain a key-value pair with the same key ([detailed below](#finding-a-key)),
117
117
- compute an index, store it into a variable `index`, and proceed as follows:
118
118
119
119
As long as the table contains a `Cell` at `index` whose status is not `Deleted` nor `Empty`, we
@@ -132,17 +132,17 @@ We only need a key and a value, and then we
132
132
!include`snippetStart="// Adding an element", snippetEnd="// Done with adding an element"` code/projects/Dictionary/Dictionary/Dictionary.cs
133
133
```
134
134
135
-
#### Finding a key {#find}
135
+
#### Finding a key
136
136
137
137
For `find`, we use a subroutine `FindI` that computes the index of a key if it exists, returns -1 otherwise.
138
138
The critical point is to understand that we *need to keep looking even if the cell is marked as `deleted`*.
139
-
We illustrate this [point below](#deleted).
139
+
We illustrate this [point below](#handling-deletion).
140
140
141
141
```{download="./code/projects/Dictionary.zip"}
142
142
!include`snippetStart="// We use a bool Find sub-routine", snippetEnd="// Done with found."` code/projects/Dictionary/Dictionary/Dictionary.cs
143
143
```
144
144
145
-
#### Handling Deleting {#deleted}
145
+
#### Handling Deletion
146
146
147
147
The `Remove` method heavily relies on `FindI`:
148
148
@@ -160,7 +160,7 @@ Imagine the following scenario:
160
160
161
161
This is the reason why we need to keep track of the deleted cells, to make sure `Find` will keep looking because it knows that possibly, when the value with key `"Lora"` was inserted, its index was already taken.
162
162
163
-
#### How is the size of the array decided? {#array-size}
163
+
#### How is the size of the array decided?
164
164
165
165
The size of the array will in general be a prime number. This is discussed in detail [on stackexchange](https://cs.stackexchange.com/a/64191), but can be easily illustrated.
0 commit comments