55#
66# Translators:
77# Jerry Chen <[email protected] >, 20178- # Freesand Leo <[email protected] >, 201998# Meng Du <[email protected] >, 2019109# iceyasha <[email protected] >, 201910+ # Freesand Leo <[email protected] >, 20191111#
1212#, fuzzy
1313msgid ""
@@ -16,7 +16,7 @@ msgstr ""
1616"Report-Msgid-Bugs-To : \n "
1717"POT-Creation-Date : 2019-09-01 14:24+0000\n "
1818"PO-Revision-Date : 2017-02-16 23:13+0000\n "
19- "Last-Translator : iceyasha <IceYasha@gmail .com>, 2019\n "
19+ "Last-Translator : Freesand Leo <yuqinju@163 .com>, 2019\n "
2020"Language-Team : Chinese (China) (https://www.transifex.com/python-doc/teams/5390/zh_CN/)\n "
2121"MIME-Version : 1.0\n "
2222"Content-Type : text/plain; charset=UTF-8\n "
@@ -47,9 +47,9 @@ msgid ""
4747"elements are considered to be infinite. The interesting property of a heap "
4848"is that its smallest element is always the root, ``heap[0]``."
4949msgstr ""
50- "堆是一个二叉树,它的每个父节点的值都只会小于或大于所有孩子节点(的值)。它使用了数组来实现:从零开始计数,对于所有的 *k* ,都有``heap[k] "
51- "<= heap[2*k+1]`` 和 ``heap[k] <= heap[2*k+2]`` "
52- "。为了便于比较,不存在的元素被认为是无限大。 堆最有趣的特性在于最小的元素总是在根结点:``heap[0]`` 。"
50+ "堆是一个二叉树,它的每个父节点的值都只会小于或大于所有孩子节点(的值)。它使用了数组来实现:从零开始计数,对于所有的 *k* ,都有 ``heap[k]"
51+ " <= heap[2*k+1]`` 和 ``heap[k] <= heap[2*k+2]``。 为了便于比较,不存在的元素被认为是无限大。 "
52+ "堆最有趣的特性在于最小的元素总是在根结点:``heap[0]``。"
5353
5454#: ../../library/heapq.rst:26
5555msgid ""
@@ -61,15 +61,17 @@ msgid ""
6161"\" max heap\" is more common in texts because of its suitability for in-place"
6262" sorting)."
6363msgstr ""
64- "这个API与教材的堆算法实现不太一样,在于两方面:(a)我们使用了基于零开始进行索引。这使得节点和其孩子节点索引之间的关系不太直观,但是更加适合"
64+ "这个API与教材的堆算法实现有所不同,具体区别有两方面:(a)我们使用了从零开始的索引。这使得节点和其孩子节点索引之间的关系不太直观但更加适合,因为 "
65+ "Python 使用从零开始的索引。 (b)我们的 pop "
66+ "方法返回最小的项而不是最大的项(这在教材中称为“最小堆”;而“最大堆”在教材中更为常见,因为它更适用于原地排序)。"
6567
6668#: ../../library/heapq.rst:33
6769msgid ""
6870"These two make it possible to view the heap as a regular Python list without"
6971" surprises: ``heap[0]`` is the smallest item, and ``heap.sort()`` maintains "
7072"the heap invariant!"
7173msgstr ""
72- "基于这两方面,把堆看作原生的Python list也没什么奇怪的: ``heap[0]`` 表示最小的元素,同时 ``heap.sort()`` "
74+ "基于这两方面,把堆看作原生的Python list也没什么奇怪的: ``heap[0]`` 表示最小的元素,同时 ``heap.sort()`` "
7375"维护了堆的不变性!"
7476
7577#: ../../library/heapq.rst:37
@@ -107,14 +109,15 @@ msgstr ""
107109
108110#: ../../library/heapq.rst:64
109111msgid "Transform list *x* into a heap, in-place, in linear time."
110- msgstr "将list *x* 转换成堆,原地,线性时间内。"
112+ msgstr "将list *x* 转换成堆,原地,线性时间内。"
111113
112114#: ../../library/heapq.rst:69
113115msgid ""
114116"Pop and return the smallest item from the *heap*, and also push the new "
115117"*item*. The heap size doesn't change. If the heap is empty, "
116118":exc:`IndexError` is raised."
117119msgstr ""
120+ "弹出并返回 *heap* 中最小的一项,同时推入新的 *item*。 堆的大小不变。 如果堆为空则引发 :exc:`IndexError`。"
118121
119122#: ../../library/heapq.rst:72
120123msgid ""
@@ -123,6 +126,8 @@ msgid ""
123126"The pop/push combination always returns an element from the heap and "
124127"replaces it with *item*."
125128msgstr ""
129+ "这个单步骤操作比 :func:`heappop` 加 :func:`heappush` 更高效,并且在使用固定大小的堆时更为适宜。 pop/push "
130+ "组合总是会从堆中返回一个元素并将其替换为 *item*。"
126131
127132#: ../../library/heapq.rst:77
128133msgid ""
@@ -131,24 +136,29 @@ msgid ""
131136"combination returns the smaller of the two values, leaving the larger value "
132137"on the heap."
133138msgstr ""
139+ "返回的值可能会比添加的 *item* 更大。 如果不希望如此,可考虑改用 :func:`heappushpop`。 它的 push/pop "
140+ "组合会返回两个值中较小的一个,将较大的值留在堆中。"
134141
135142#: ../../library/heapq.rst:83
136143msgid "The module also offers three general purpose functions based on heaps."
137- msgstr ""
144+ msgstr "该模块还提供了三个基于堆的通用功能函数。 "
138145
139146#: ../../library/heapq.rst:88
140147msgid ""
141148"Merge multiple sorted inputs into a single sorted output (for example, merge"
142149" timestamped entries from multiple log files). Returns an :term:`iterator` "
143150"over the sorted values."
144151msgstr ""
152+ "将多个已排序的输入合并为一个已排序的输出(例如,合并来自多个日志文件的带时间戳的条目)。 返回已排序值的 :term:`iterator`。"
145153
146154#: ../../library/heapq.rst:92
147155msgid ""
148156"Similar to ``sorted(itertools.chain(*iterables))`` but returns an iterable, "
149157"does not pull the data into memory all at once, and assumes that each of the"
150158" input streams is already sorted (smallest to largest)."
151159msgstr ""
160+ "类似于 ``sorted(itertools.chain(*iterables))`` "
161+ "但返回一个可迭代对象,不会一次性地将数据全部放入内存,并假定每个输入流都是已排序的(从小到大)。"
152162
153163#: ../../library/heapq.rst:96
154164msgid ""
@@ -161,6 +171,8 @@ msgid ""
161171"extract a comparison key from each input element. The default value is "
162172"``None`` (compare the elements directly)."
163173msgstr ""
174+ "*key* 指定带有单个参数的 :term:`key function`,用于从每个输入元素中提取比较键。 默认值为 ``None`` "
175+ "(直接比较元素)。"
164176
165177#: ../../library/heapq.rst:102
166178msgid ""
@@ -169,10 +181,13 @@ msgid ""
169181"to ``sorted(itertools.chain(*iterables), reverse=True)``, all iterables must"
170182" be sorted from largest to smallest."
171183msgstr ""
184+ "*reverse* 为一个布尔值。 如果设为 ``True``,则输入元素将按比较结果逆序进行合并。 要达成与 "
185+ "``sorted(itertools.chain(*iterables), reverse=True)`` "
186+ "类似的行为,所有可迭代对象必须是已从大到小排序的。"
172187
173188#: ../../library/heapq.rst:107
174189msgid "Added the optional *key* and *reverse* parameters."
175- msgstr ""
190+ msgstr "添加了可选的 *key* 和 *reverse* 形参。 "
176191
177192#: ../../library/heapq.rst:113
178193msgid ""
@@ -182,6 +197,9 @@ msgid ""
182197"example, ``key=str.lower``). Equivalent to: ``sorted(iterable, key=key, "
183198"reverse=True)[:n]``."
184199msgstr ""
200+ "从 *iterable* 所定义的数据集中返回前 *n* 个最大元素组成的列表。 如果提供了 *key* 则其应指定一个单参数的函数,用于从 "
201+ "*iterable* 的每个元素中提取比较键 (例如 ``key=str.lower``)。 等价于: ``sorted(iterable, "
202+ "key=key, reverse=True)[:n]``。"
185203
186204#: ../../library/heapq.rst:122
187205msgid ""
@@ -191,6 +209,9 @@ msgid ""
191209"example, ``key=str.lower``). Equivalent to: ``sorted(iterable, "
192210"key=key)[:n]``."
193211msgstr ""
212+ "从 *iterable* 所定义的数据集中返回前 *n* 个最小元素组成的列表。 如果提供了 *key* 则其应指定一个单参数的函数,用于从 "
213+ "*iterable* 的每个元素中提取比较键 (例如 ``key=str.lower``)。 等价于: ``sorted(iterable, "
214+ "key=key)[:n]``。"
194215
195216#: ../../library/heapq.rst:128
196217msgid ""
@@ -200,6 +221,8 @@ msgid ""
200221":func:`max` functions. If repeated usage of these functions is required, "
201222"consider turning the iterable into an actual heap."
202223msgstr ""
224+ "后两个函数在 *n* 值较小时性能最好。 对于更大的值,使用 :func:`sorted` 函数会更有效率。 此外,当 ``n==1`` 时,使用内置的"
225+ " :func:`min` 和 :func:`max` 函数会更有效率。 如果需要重复使用这些函数,请考虑将可迭代对象转为真正的堆。"
203226
204227#: ../../library/heapq.rst:136
205228msgid "Basic Examples"
@@ -211,52 +234,55 @@ msgid ""
211234" pushing all values onto a heap and then popping off the smallest values one"
212235" at a time::"
213236msgstr ""
237+ "`堆排序 <https://en.wikipedia.org/wiki/Heapsort>`_ 可以通过将所有值推入堆中然后每次弹出一个最小值项来实现。"
214238
215239#: ../../library/heapq.rst:151
216240msgid ""
217241"This is similar to ``sorted(iterable)``, but unlike :func:`sorted`, this "
218242"implementation is not stable."
219- msgstr ""
243+ msgstr "这类似于 ``sorted(iterable)``,但与 :func:`sorted` 不同的是这个实现是不稳定的。 "
220244
221245#: ../../library/heapq.rst:154
222246msgid ""
223247"Heap elements can be tuples. This is useful for assigning comparison values"
224248" (such as task priorities) alongside the main record being tracked::"
225- msgstr ""
249+ msgstr "堆元素可以为元组。 这适用于将比较值(例如任务优先级)与跟踪的主记录进行赋值的场合:: "
226250
227251#: ../../library/heapq.rst:167
228252msgid "Priority Queue Implementation Notes"
229- msgstr ""
253+ msgstr "优先队列实现说明 "
230254
231255#: ../../library/heapq.rst:169
232256msgid ""
233257"A `priority queue <https://en.wikipedia.org/wiki/Priority_queue>`_ is common"
234258" use for a heap, and it presents several implementation challenges:"
235259msgstr ""
260+ "`优先队列 <https://en.wikipedia.org/wiki/Priority_queue>`_ "
261+ "是堆的常用场合,并且它的实现包含了多个挑战:"
236262
237263#: ../../library/heapq.rst:172
238264msgid ""
239265"Sort stability: how do you get two tasks with equal priorities to be "
240266"returned in the order they were originally added?"
241- msgstr ""
267+ msgstr "排序稳定性:你该如何令相同优先级的两个任务按它们最初被加入时的顺序返回? "
242268
243269#: ../../library/heapq.rst:175
244270msgid ""
245271"Tuple comparison breaks for (priority, task) pairs if the priorities are "
246272"equal and the tasks do not have a default comparison order."
247- msgstr ""
273+ msgstr "如果优先级相同且任务没有默认比较顺序,则 (priority, task) 对的元组比较将会中断。 "
248274
249275#: ../../library/heapq.rst:178
250276msgid ""
251277"If the priority of a task changes, how do you move it to a new position in "
252278"the heap?"
253- msgstr ""
279+ msgstr "如果任务优先级发生改变,你该如何将其移至堆中的新位置? "
254280
255281#: ../../library/heapq.rst:181
256282msgid ""
257283"Or if a pending task needs to be deleted, how do you find it and remove it "
258284"from the queue?"
259- msgstr ""
285+ msgstr "或者如果一个挂起的任务需要被删除,你该如何找到它并将其移出队列? "
260286
261287#: ../../library/heapq.rst:184
262288msgid ""
@@ -267,31 +293,35 @@ msgid ""
267293" same, the tuple comparison will never attempt to directly compare two "
268294"tasks."
269295msgstr ""
296+ "针对前两项挑战的一种解决方案是将条目保存为包含优先级、条目计数和任务对象 3 个元素的列表。 "
297+ "条目计数可用来打破平局,这样具有相同优先级的任务将按它们的添加顺序返回。 并且由于没有哪两个条目计数是相同的,元组比较将永远不会直接比较两个任务。"
270298
271299#: ../../library/heapq.rst:190
272300msgid ""
273301"Another solution to the problem of non-comparable tasks is to create a "
274302"wrapper class that ignores the task item and only compares the priority "
275303"field::"
276- msgstr ""
304+ msgstr "不可比较任务问题的另一种解决方案是创建一个忽略任务条目并且只比较优先级字段的包装器类:: "
277305
278306#: ../../library/heapq.rst:201
279307msgid ""
280308"The remaining challenges revolve around finding a pending task and making "
281309"changes to its priority or removing it entirely. Finding a task can be done"
282310" with a dictionary pointing to an entry in the queue."
283- msgstr ""
311+ msgstr "其余的挑战主要包括找到挂起的任务并修改其优先级或将其完全移除。 找到一个任务可使用一个指向队列中条目的字典来实现。 "
284312
285313#: ../../library/heapq.rst:205
286314msgid ""
287315"Removing the entry or changing its priority is more difficult because it "
288316"would break the heap structure invariants. So, a possible solution is to "
289317"mark the entry as removed and add a new entry with the revised priority::"
290318msgstr ""
319+ "移除条目或改变其优先级的操作实现起来更为困难,因为它会破坏堆结构不变量。 "
320+ "因此,一种可能的解决方案是将条目标记为已移除,再添加一个改变了优先级的新条目::"
291321
292322#: ../../library/heapq.rst:239
293323msgid "Theory"
294- msgstr ""
324+ msgstr "理论 "
295325
296326#: ../../library/heapq.rst:241
297327msgid ""
@@ -300,12 +330,14 @@ msgid ""
300330"existing elements are considered to be infinite. The interesting property "
301331"of a heap is that ``a[0]`` is always its smallest element."
302332msgstr ""
333+ "堆是通过数组来实现的,其中的元素从 0 开始计数,对于所有的 *k* 都有 ``a[k] <= a[2*k+1]`` 且 ``a[k] <= "
334+ "a[2*k+2]``。 为了便于比较,不存在的元素被视为无穷大。 堆最有趣的特性在于 ``a[0]`` 总是其中最小的元素。"
303335
304336#: ../../library/heapq.rst:246
305337msgid ""
306338"The strange invariant above is meant to be an efficient memory "
307339"representation for a tournament. The numbers below are *k*, not ``a[k]``::"
308- msgstr ""
340+ msgstr "上面的特殊不变量是用来作为一场锦标赛的高效内存表示。 下面的数字是 *k* 而不是 ``a[k]``:: "
309341
310342#: ../../library/heapq.rst:259
311343msgid ""
0 commit comments