Skip to content

Commit aa3e73b

Browse files
serhiy-storchakaGlyphack
authored andcommitted
pythongh-113664: Improve style of Big O notation (pythonGH-113695)
Use cursive to make it looking like mathematic formulas.
1 parent 954507f commit aa3e73b

File tree

16 files changed

+27
-27
lines changed

16 files changed

+27
-27
lines changed

Doc/faq/design.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ on the key and a per-process seed; for example, ``'Python'`` could hash to
451451
to ``1142331976``. The hash code is then used to calculate a location in an
452452
internal array where the value will be stored. Assuming that you're storing
453453
keys that all have different hash values, this means that dictionaries take
454-
constant time -- O(1), in Big-O notation -- to retrieve a key.
454+
constant time -- *O*\ (1), in Big-O notation -- to retrieve a key.
455455

456456

457457
Why must dictionary keys be immutable?

Doc/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ Glossary
742742
list
743743
A built-in Python :term:`sequence`. Despite its name it is more akin
744744
to an array in other languages than to a linked list since access to
745-
elements is O(1).
745+
elements is *O*\ (1).
746746

747747
list comprehension
748748
A compact way to process all or part of the elements in a sequence and

Doc/library/asyncio-policy.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ implementation used by the asyncio event loop:
237237

238238
It works reliably even when the asyncio event loop is run in a non-main OS thread.
239239

240-
There is no noticeable overhead when handling a big number of children (*O(1)* each
240+
There is no noticeable overhead when handling a big number of children (*O*\ (1) each
241241
time a child terminates), but starting a thread per process requires extra memory.
242242

243243
This watcher is used by default.
@@ -257,7 +257,7 @@ implementation used by the asyncio event loop:
257257
watcher is installed.
258258

259259
The solution is safe but it has a significant overhead when
260-
handling a big number of processes (*O(n)* each time a
260+
handling a big number of processes (*O*\ (*n*) each time a
261261
:py:data:`SIGCHLD` is received).
262262

263263
.. versionadded:: 3.8
@@ -273,7 +273,7 @@ implementation used by the asyncio event loop:
273273
The watcher avoids disrupting other code spawning processes
274274
by polling every process explicitly on a :py:data:`SIGCHLD` signal.
275275

276-
This solution is as safe as :class:`MultiLoopChildWatcher` and has the same *O(N)*
276+
This solution is as safe as :class:`MultiLoopChildWatcher` and has the same *O*\ (*n*)
277277
complexity but requires a running event loop in the main thread to work.
278278

279279
.. deprecated:: 3.12
@@ -285,7 +285,7 @@ implementation used by the asyncio event loop:
285285
processes and waiting for their termination.
286286

287287
There is no noticeable overhead when handling a big number of
288-
children (*O(1)* each time a child terminates).
288+
children (*O*\ (1) each time a child terminates).
289289

290290
This solution requires a running event loop in the main thread to work, as
291291
:class:`SafeChildWatcher`.

Doc/library/bisect.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The following functions are provided:
7979
To support inserting records in a table, the *key* function (if any) is
8080
applied to *x* for the search step but not for the insertion step.
8181

82-
Keep in mind that the ``O(log n)`` search is dominated by the slow O(n)
82+
Keep in mind that the *O*\ (log *n*) search is dominated by the slow *O*\ (*n*)
8383
insertion step.
8484

8585
.. versionchanged:: 3.10
@@ -99,7 +99,7 @@ The following functions are provided:
9999
To support inserting records in a table, the *key* function (if any) is
100100
applied to *x* for the search step but not for the insertion step.
101101

102-
Keep in mind that the ``O(log n)`` search is dominated by the slow O(n)
102+
Keep in mind that the *O*\ (log *n*) search is dominated by the slow *O*\ (*n*)
103103
insertion step.
104104

105105
.. versionchanged:: 3.10
@@ -115,7 +115,7 @@ thoughts in mind:
115115
* Bisection is effective for searching ranges of values.
116116
For locating specific values, dictionaries are more performant.
117117

118-
* The *insort()* functions are ``O(n)`` because the logarithmic search step
118+
* The *insort()* functions are *O*\ (*n*) because the logarithmic search step
119119
is dominated by the linear time insertion step.
120120

121121
* The search functions are stateless and discard key function results after

Doc/library/collections.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ or subtracting from an empty counter.
458458
Deques are a generalization of stacks and queues (the name is pronounced "deck"
459459
and is short for "double-ended queue"). Deques support thread-safe, memory
460460
efficient appends and pops from either side of the deque with approximately the
461-
same O(1) performance in either direction.
461+
same *O*\ (1) performance in either direction.
462462

463463
Though :class:`list` objects support similar operations, they are optimized for
464-
fast fixed-length operations and incur O(n) memory movement costs for
464+
fast fixed-length operations and incur *O*\ (*n*) memory movement costs for
465465
``pop(0)`` and ``insert(0, v)`` operations which change both the size and
466466
position of the underlying data representation.
467467

@@ -585,7 +585,7 @@ or subtracting from an empty counter.
585585
In addition to the above, deques support iteration, pickling, ``len(d)``,
586586
``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
587587
the :keyword:`in` operator, and subscript references such as ``d[0]`` to access
588-
the first element. Indexed access is O(1) at both ends but slows to O(n) in
588+
the first element. Indexed access is *O*\ (1) at both ends but slows to *O*\ (*n*) in
589589
the middle. For fast random access, use lists instead.
590590

591591
Starting in version 3.5, deques support ``__add__()``, ``__mul__()``,

Doc/library/contextvars.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Manual Context Management
131131
ctx: Context = copy_context()
132132
print(list(ctx.items()))
133133

134-
The function has an O(1) complexity, i.e. works equally fast for
134+
The function has an *O*\ (1) complexity, i.e. works equally fast for
135135
contexts with a few context variables and for contexts that have
136136
a lot of them.
137137

Doc/library/heapq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ winner. The simplest algorithmic way to remove it and find the "next" winner is
270270
to move some loser (let's say cell 30 in the diagram above) into the 0 position,
271271
and then percolate this new 0 down the tree, exchanging values, until the
272272
invariant is re-established. This is clearly logarithmic on the total number of
273-
items in the tree. By iterating over all items, you get an O(n log n) sort.
273+
items in the tree. By iterating over all items, you get an *O*\ (*n* log *n*) sort.
274274

275275
A nice feature of this sort is that you can efficiently insert new items while
276276
the sort is going on, provided that the inserted items are not "better" than the

Doc/library/select.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ The module defines the following:
185185
-----------------------------
186186

187187
Solaris and derivatives have ``/dev/poll``. While :c:func:`!select` is
188-
O(highest file descriptor) and :c:func:`!poll` is O(number of file
189-
descriptors), ``/dev/poll`` is O(active file descriptors).
188+
*O*\ (*highest file descriptor*) and :c:func:`!poll` is *O*\ (*number of file
189+
descriptors*), ``/dev/poll`` is *O*\ (*active file descriptors*).
190190

191191
``/dev/poll`` behaviour is very close to the standard :c:func:`!poll`
192192
object.
@@ -381,8 +381,8 @@ scalability for network servers that service many, many clients at the same
381381
time. :c:func:`!poll` scales better because the system call only requires listing
382382
the file descriptors of interest, while :c:func:`!select` builds a bitmap, turns
383383
on bits for the fds of interest, and then afterward the whole bitmap has to be
384-
linearly scanned again. :c:func:`!select` is O(highest file descriptor), while
385-
:c:func:`!poll` is O(number of file descriptors).
384+
linearly scanned again. :c:func:`!select` is *O*\ (*highest file descriptor*), while
385+
:c:func:`!poll` is *O*\ (*number of file descriptors*).
386386

387387

388388
.. method:: poll.register(fd[, eventmask])

Doc/reference/datamodel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ Basic customization
18761876

18771877
This is intended to provide protection against a denial-of-service caused
18781878
by carefully chosen inputs that exploit the worst case performance of a
1879-
dict insertion, O(n\ :sup:`2`) complexity. See
1879+
dict insertion, *O*\ (*n*\ :sup:`2`) complexity. See
18801880
http://ocert.org/advisories/ocert-2011-003.html for details.
18811881

18821882
Changing hash values affects the iteration order of sets.

Doc/using/cmdline.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ Miscellaneous options
369369

370370
Hash randomization is intended to provide protection against a
371371
denial-of-service caused by carefully chosen inputs that exploit the worst
372-
case performance of a dict construction, O(n\ :sup:`2`) complexity. See
372+
case performance of a dict construction, *O*\ (*n*\ :sup:`2`) complexity. See
373373
http://ocert.org/advisories/ocert-2011-003.html for details.
374374

375375
:envvar:`PYTHONHASHSEED` allows you to set a fixed value for the hash

0 commit comments

Comments
 (0)