Skip to content

Commit 67d17d6

Browse files
heikkitoivonencodex
andcommitted
Fix: Correct stdlib complexity documentation details
Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Codex <codex@openai.com>
1 parent 38954c6 commit 67d17d6

4 files changed

Lines changed: 15 additions & 17 deletions

File tree

docs/stdlib/concurrent_futures.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The `concurrent.futures` module provides high-level interfaces for asynchronousl
1212
| `executor.submit(fn, *args)` | O(1) | O(1) | Submit task to queue |
1313
| `executor.map(fn, iterable)` | O(n) | O(n) | Submit all tasks, n = item count |
1414
| `Future.result()` | O(1) | O(r) | Get result, r = result size |
15-
| `as_completed(futures)` | O(n log n) | O(n) | Heap-based iteration; yields as each completes |
15+
| `as_completed(futures)` | O(n log n) | O(n) | Sorts futures by id for lock ordering, then event-based iteration |
1616
| `wait(futures)` | O(n) | O(n) | Wait for futures |
1717
| `Executor` creation | O(1) | O(1) | Base class init |
1818
| `Future` creation | O(1) | O(1) | Pending future |
@@ -185,9 +185,9 @@ executor = ThreadPoolExecutor(max_workers=4)
185185
# Submit all tasks: O(n)
186186
futures = [executor.submit(task, i) for i in range(100)] # O(n)
187187

188-
# Get futures as they complete: O(n log n) for sorting
189-
# (maintains heap of pending futures)
190-
for future in as_completed(futures): # O(n log n) time
188+
# Get futures as they complete: O(n log n) overall
189+
# (initial lock-order sorting + event-based waiter)
190+
for future in as_completed(futures): # O(n log n) total
191191
result = future.result() # O(1) per future
192192
process(result)
193193
```
@@ -293,7 +293,7 @@ def process_with_timeout(items, timeout=30):
293293
# Submit all: O(n)
294294
futures = {executor.submit(task, item): item for item in items}
295295

296-
# Wait with timeout: O(n)
296+
# Wait with timeout: O(n log n) overall
297297
try:
298298
for future in as_completed(futures, timeout=timeout): # O(n log n)
299299
result = future.result()

docs/stdlib/gzip.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ import gzip
153153
data = b'x' * 1000000
154154
compressed = gzip.compress(data, compresslevel=1) # Fastest
155155

156-
# Compression level 6 (default): O(n)
156+
# Compression level 6 (balanced): O(n)
157157
compressed = gzip.compress(data, compresslevel=6) # Balanced
158158

159-
# Compression level 9 (best): O(n) but with higher constant factor
159+
# Compression level 9 (default, best): O(n) but with higher constant factor
160160
compressed = gzip.compress(data, compresslevel=9) # Slowest, best ratio
161161
```
162162

@@ -291,7 +291,7 @@ with gzip.open('text.gz', 'rb') as f: # 'b' = binary
291291
```python
292292
import gzip
293293

294-
# For streaming: use default (6)
294+
# For streaming: use default (9)
295295
# Already optimized for sequential compression
296296

297297
# For one-shot:
@@ -303,7 +303,7 @@ compressed = gzip.compress(data, compresslevel=1) # Fastest
303303
# Storage critical: level 9
304304
compressed = gzip.compress(data, compresslevel=9) # Best ratio
305305

306-
# Default: level 6 (good balance)
306+
# Default: level 9 (best compression)
307307
compressed = gzip.compress(data)
308308
```
309309

docs/stdlib/hashlib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import hashlib
3737
data = b"test"
3838

3939
# MD5 - O(n)
40-
h1 = hashlib.md5(data) # O(4) - deprecated
40+
h1 = hashlib.md5(data) # O(4) - cryptographically broken
4141

4242
# SHA1 - O(n)
4343
h2 = hashlib.sha1(data) # O(4)

docs/stdlib/io.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,12 @@ print(stream.tell()) # 6
139139
# Read from position - O(n)
140140
print(stream.read()) # "World"
141141

142-
# Seek from end - O(1)
143-
stream.seek(-5, 2) # 2 = os.SEEK_END
144-
print(stream.read()) # "World"
142+
# Seek to end - O(1)
143+
stream.seek(0, 2) # 2 = os.SEEK_END (only offset=0 allowed for text streams)
144+
print(stream.tell()) # 11
145145

146-
# Seek from current - O(1)
147-
stream.seek(0)
148-
stream.read(5) # Read "Hello"
149-
stream.seek(1, 1) # 1 = os.SEEK_CUR
146+
# Seek to absolute position - O(1)
147+
stream.seek(6)
150148
print(stream.read()) # "World"
151149
```
152150

0 commit comments

Comments
 (0)