k3priorityqueue 0.1.2__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- k3priorityqueue-0.1.4/LICENSE +21 -0
- k3priorityqueue-0.1.4/PKG-INFO +143 -0
- k3priorityqueue-0.1.4/README.md +105 -0
- {k3priorityqueue-0.1.2/k3priorityqueue → k3priorityqueue-0.1.4}/__init__.py +6 -13
- k3priorityqueue-0.1.4/k3priorityqueue.egg-info/PKG-INFO +143 -0
- k3priorityqueue-0.1.4/k3priorityqueue.egg-info/SOURCES.txt +16 -0
- k3priorityqueue-0.1.4/k3priorityqueue.egg-info/requires.txt +18 -0
- {k3priorityqueue-0.1.2/k3priorityqueue → k3priorityqueue-0.1.4}/priorityqueue.py +9 -13
- k3priorityqueue-0.1.4/pyproject.toml +61 -0
- {k3priorityqueue-0.1.2/k3priorityqueue → k3priorityqueue-0.1.4}/synopsis.py +3 -3
- k3priorityqueue-0.1.4/test/test_doctest.py +8 -0
- k3priorityqueue-0.1.4/test/test_k3priorityqueue.py +233 -0
- k3priorityqueue-0.1.2/PKG-INFO +0 -124
- k3priorityqueue-0.1.2/k3priorityqueue/setup.py +0 -23
- k3priorityqueue-0.1.2/k3priorityqueue.egg-info/PKG-INFO +0 -124
- k3priorityqueue-0.1.2/k3priorityqueue.egg-info/SOURCES.txt +0 -10
- k3priorityqueue-0.1.2/k3priorityqueue.egg-info/requires.txt +0 -3
- k3priorityqueue-0.1.2/setup.py +0 -23
- {k3priorityqueue-0.1.2 → k3priorityqueue-0.1.4}/k3priorityqueue.egg-info/dependency_links.txt +0 -0
- {k3priorityqueue-0.1.2 → k3priorityqueue-0.1.4}/k3priorityqueue.egg-info/top_level.txt +0 -0
- {k3priorityqueue-0.1.2 → k3priorityqueue-0.1.4}/setup.cfg +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 张炎泼
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: k3priorityqueue
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Priority queue with weighted producer support
|
|
5
|
+
Author-email: Zhang Yanpo <drdr.xp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pykit3/k3priorityqueue
|
|
8
|
+
Project-URL: Documentation, https://k3priorityqueue.readthedocs.io
|
|
9
|
+
Keywords: queue,priority-queue,producer,weighted
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: k3heap
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff; extra == "dev"
|
|
26
|
+
Requires-Dist: coverage; extra == "dev"
|
|
27
|
+
Requires-Dist: k3ut; extra == "dev"
|
|
28
|
+
Requires-Dist: k3thread; extra == "dev"
|
|
29
|
+
Provides-Extra: publish
|
|
30
|
+
Requires-Dist: build; extra == "publish"
|
|
31
|
+
Requires-Dist: twine; extra == "publish"
|
|
32
|
+
Requires-Dist: pk3; extra == "publish"
|
|
33
|
+
Provides-Extra: docs
|
|
34
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
35
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
36
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# k3priorityqueue
|
|
40
|
+
|
|
41
|
+
[](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)
|
|
42
|
+
[](https://travis-ci.com/pykit3/k3priorityqueue)
|
|
43
|
+
[](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)
|
|
44
|
+
[](https://pypi.org/project/k3priorityqueue)
|
|
45
|
+
|
|
46
|
+
priorityQueue is a queue with priority support
|
|
47
|
+
|
|
48
|
+
k3priorityqueue is a component of [pykit3] project: a python3 toolkit set.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
PriorityQueue is a queue with priority support:
|
|
52
|
+
|
|
53
|
+
The numbers of items it pops from each producer matches exactly the ratio of their priority:
|
|
54
|
+
If the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long
|
|
55
|
+
enough, it is expected that the number of items popped from A, B and C are
|
|
56
|
+
1:3:7.
|
|
57
|
+
|
|
58
|
+
import k3priorityqueue
|
|
59
|
+
|
|
60
|
+
producers = (
|
|
61
|
+
# id, priority, iterable
|
|
62
|
+
(1, 1, [1] * 10),
|
|
63
|
+
(2, 2, [2] * 10),
|
|
64
|
+
(3, 3, [3] * 10),
|
|
65
|
+
)
|
|
66
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
67
|
+
for pid, prio, itr in producers:
|
|
68
|
+
pq.add_producer(pid, prio, itr)
|
|
69
|
+
|
|
70
|
+
count = {}
|
|
71
|
+
for _ in range(12):
|
|
72
|
+
val = pq.get()
|
|
73
|
+
count[val] = count.get(val, 0) + 1
|
|
74
|
+
print(val)
|
|
75
|
+
|
|
76
|
+
print('respect priority ratio: counts:', repr(count))
|
|
77
|
+
|
|
78
|
+
while True:
|
|
79
|
+
try:
|
|
80
|
+
val = pq.get()
|
|
81
|
+
except k3priorityqueue.Empty as e:
|
|
82
|
+
break
|
|
83
|
+
count[val] = count.get(val, 0) + 1
|
|
84
|
+
print(val)
|
|
85
|
+
|
|
86
|
+
print('consumed all: counts:', repr(count))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# Install
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
pip install k3priorityqueue
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
# Synopsis
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
|
|
101
|
+
import k3priorityqueue
|
|
102
|
+
|
|
103
|
+
producers = (
|
|
104
|
+
# id, priority, iterable
|
|
105
|
+
(1, 1, [1] * 10),
|
|
106
|
+
(2, 2, [2] * 10),
|
|
107
|
+
(3, 3, [3] * 10),
|
|
108
|
+
)
|
|
109
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
110
|
+
for pid, prio, itr in producers:
|
|
111
|
+
pq.add_producer(pid, prio, itr)
|
|
112
|
+
|
|
113
|
+
count = {}
|
|
114
|
+
for _ in range(12):
|
|
115
|
+
val = pq.get()
|
|
116
|
+
count[val] = count.get(val, 0) + 1
|
|
117
|
+
print(val)
|
|
118
|
+
|
|
119
|
+
print('respect priority ratio: counts:', repr(count))
|
|
120
|
+
|
|
121
|
+
while True:
|
|
122
|
+
try:
|
|
123
|
+
val = pq.get()
|
|
124
|
+
except k3priorityqueue.Empty as e:
|
|
125
|
+
break
|
|
126
|
+
count[val] = count.get(val, 0) + 1
|
|
127
|
+
print(val)
|
|
128
|
+
|
|
129
|
+
print('consumed all: counts:', repr(count))
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
# Author
|
|
133
|
+
|
|
134
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
135
|
+
|
|
136
|
+
# Copyright and License
|
|
137
|
+
|
|
138
|
+
The MIT License (MIT)
|
|
139
|
+
|
|
140
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# k3priorityqueue
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)
|
|
4
|
+
[](https://travis-ci.com/pykit3/k3priorityqueue)
|
|
5
|
+
[](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)
|
|
6
|
+
[](https://pypi.org/project/k3priorityqueue)
|
|
7
|
+
|
|
8
|
+
priorityQueue is a queue with priority support
|
|
9
|
+
|
|
10
|
+
k3priorityqueue is a component of [pykit3] project: a python3 toolkit set.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
PriorityQueue is a queue with priority support:
|
|
14
|
+
|
|
15
|
+
The numbers of items it pops from each producer matches exactly the ratio of their priority:
|
|
16
|
+
If the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long
|
|
17
|
+
enough, it is expected that the number of items popped from A, B and C are
|
|
18
|
+
1:3:7.
|
|
19
|
+
|
|
20
|
+
import k3priorityqueue
|
|
21
|
+
|
|
22
|
+
producers = (
|
|
23
|
+
# id, priority, iterable
|
|
24
|
+
(1, 1, [1] * 10),
|
|
25
|
+
(2, 2, [2] * 10),
|
|
26
|
+
(3, 3, [3] * 10),
|
|
27
|
+
)
|
|
28
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
29
|
+
for pid, prio, itr in producers:
|
|
30
|
+
pq.add_producer(pid, prio, itr)
|
|
31
|
+
|
|
32
|
+
count = {}
|
|
33
|
+
for _ in range(12):
|
|
34
|
+
val = pq.get()
|
|
35
|
+
count[val] = count.get(val, 0) + 1
|
|
36
|
+
print(val)
|
|
37
|
+
|
|
38
|
+
print('respect priority ratio: counts:', repr(count))
|
|
39
|
+
|
|
40
|
+
while True:
|
|
41
|
+
try:
|
|
42
|
+
val = pq.get()
|
|
43
|
+
except k3priorityqueue.Empty as e:
|
|
44
|
+
break
|
|
45
|
+
count[val] = count.get(val, 0) + 1
|
|
46
|
+
print(val)
|
|
47
|
+
|
|
48
|
+
print('consumed all: counts:', repr(count))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Install
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
pip install k3priorityqueue
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
# Synopsis
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
|
|
63
|
+
import k3priorityqueue
|
|
64
|
+
|
|
65
|
+
producers = (
|
|
66
|
+
# id, priority, iterable
|
|
67
|
+
(1, 1, [1] * 10),
|
|
68
|
+
(2, 2, [2] * 10),
|
|
69
|
+
(3, 3, [3] * 10),
|
|
70
|
+
)
|
|
71
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
72
|
+
for pid, prio, itr in producers:
|
|
73
|
+
pq.add_producer(pid, prio, itr)
|
|
74
|
+
|
|
75
|
+
count = {}
|
|
76
|
+
for _ in range(12):
|
|
77
|
+
val = pq.get()
|
|
78
|
+
count[val] = count.get(val, 0) + 1
|
|
79
|
+
print(val)
|
|
80
|
+
|
|
81
|
+
print('respect priority ratio: counts:', repr(count))
|
|
82
|
+
|
|
83
|
+
while True:
|
|
84
|
+
try:
|
|
85
|
+
val = pq.get()
|
|
86
|
+
except k3priorityqueue.Empty as e:
|
|
87
|
+
break
|
|
88
|
+
count[val] = count.get(val, 0) + 1
|
|
89
|
+
print(val)
|
|
90
|
+
|
|
91
|
+
print('consumed all: counts:', repr(count))
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Author
|
|
95
|
+
|
|
96
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
97
|
+
|
|
98
|
+
# Copyright and License
|
|
99
|
+
|
|
100
|
+
The MIT License (MIT)
|
|
101
|
+
|
|
102
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -42,27 +42,20 @@ while True:
|
|
|
42
42
|
print('consumed all: counts:', repr(count))
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
# from .proc import ProcError
|
|
45
|
+
from importlib.metadata import version
|
|
47
46
|
|
|
48
|
-
__version__ = "
|
|
49
|
-
__name__ = "k3priorityqueue"
|
|
47
|
+
__version__ = version("k3priorityqueue")
|
|
50
48
|
|
|
51
49
|
from .priorityqueue import (
|
|
52
50
|
Empty,
|
|
53
|
-
|
|
54
51
|
Producer,
|
|
55
52
|
PriorityQueue,
|
|
56
|
-
|
|
57
53
|
default_priority,
|
|
58
54
|
)
|
|
59
55
|
|
|
60
56
|
__all__ = [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
'default_priority',
|
|
57
|
+
"Empty",
|
|
58
|
+
"Producer",
|
|
59
|
+
"PriorityQueue",
|
|
60
|
+
"default_priority",
|
|
67
61
|
]
|
|
68
|
-
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: k3priorityqueue
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Priority queue with weighted producer support
|
|
5
|
+
Author-email: Zhang Yanpo <drdr.xp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pykit3/k3priorityqueue
|
|
8
|
+
Project-URL: Documentation, https://k3priorityqueue.readthedocs.io
|
|
9
|
+
Keywords: queue,priority-queue,producer,weighted
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: k3heap
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff; extra == "dev"
|
|
26
|
+
Requires-Dist: coverage; extra == "dev"
|
|
27
|
+
Requires-Dist: k3ut; extra == "dev"
|
|
28
|
+
Requires-Dist: k3thread; extra == "dev"
|
|
29
|
+
Provides-Extra: publish
|
|
30
|
+
Requires-Dist: build; extra == "publish"
|
|
31
|
+
Requires-Dist: twine; extra == "publish"
|
|
32
|
+
Requires-Dist: pk3; extra == "publish"
|
|
33
|
+
Provides-Extra: docs
|
|
34
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
35
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
36
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# k3priorityqueue
|
|
40
|
+
|
|
41
|
+
[](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)
|
|
42
|
+
[](https://travis-ci.com/pykit3/k3priorityqueue)
|
|
43
|
+
[](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)
|
|
44
|
+
[](https://pypi.org/project/k3priorityqueue)
|
|
45
|
+
|
|
46
|
+
priorityQueue is a queue with priority support
|
|
47
|
+
|
|
48
|
+
k3priorityqueue is a component of [pykit3] project: a python3 toolkit set.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
PriorityQueue is a queue with priority support:
|
|
52
|
+
|
|
53
|
+
The numbers of items it pops from each producer matches exactly the ratio of their priority:
|
|
54
|
+
If the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long
|
|
55
|
+
enough, it is expected that the number of items popped from A, B and C are
|
|
56
|
+
1:3:7.
|
|
57
|
+
|
|
58
|
+
import k3priorityqueue
|
|
59
|
+
|
|
60
|
+
producers = (
|
|
61
|
+
# id, priority, iterable
|
|
62
|
+
(1, 1, [1] * 10),
|
|
63
|
+
(2, 2, [2] * 10),
|
|
64
|
+
(3, 3, [3] * 10),
|
|
65
|
+
)
|
|
66
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
67
|
+
for pid, prio, itr in producers:
|
|
68
|
+
pq.add_producer(pid, prio, itr)
|
|
69
|
+
|
|
70
|
+
count = {}
|
|
71
|
+
for _ in range(12):
|
|
72
|
+
val = pq.get()
|
|
73
|
+
count[val] = count.get(val, 0) + 1
|
|
74
|
+
print(val)
|
|
75
|
+
|
|
76
|
+
print('respect priority ratio: counts:', repr(count))
|
|
77
|
+
|
|
78
|
+
while True:
|
|
79
|
+
try:
|
|
80
|
+
val = pq.get()
|
|
81
|
+
except k3priorityqueue.Empty as e:
|
|
82
|
+
break
|
|
83
|
+
count[val] = count.get(val, 0) + 1
|
|
84
|
+
print(val)
|
|
85
|
+
|
|
86
|
+
print('consumed all: counts:', repr(count))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# Install
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
pip install k3priorityqueue
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
# Synopsis
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
|
|
101
|
+
import k3priorityqueue
|
|
102
|
+
|
|
103
|
+
producers = (
|
|
104
|
+
# id, priority, iterable
|
|
105
|
+
(1, 1, [1] * 10),
|
|
106
|
+
(2, 2, [2] * 10),
|
|
107
|
+
(3, 3, [3] * 10),
|
|
108
|
+
)
|
|
109
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
110
|
+
for pid, prio, itr in producers:
|
|
111
|
+
pq.add_producer(pid, prio, itr)
|
|
112
|
+
|
|
113
|
+
count = {}
|
|
114
|
+
for _ in range(12):
|
|
115
|
+
val = pq.get()
|
|
116
|
+
count[val] = count.get(val, 0) + 1
|
|
117
|
+
print(val)
|
|
118
|
+
|
|
119
|
+
print('respect priority ratio: counts:', repr(count))
|
|
120
|
+
|
|
121
|
+
while True:
|
|
122
|
+
try:
|
|
123
|
+
val = pq.get()
|
|
124
|
+
except k3priorityqueue.Empty as e:
|
|
125
|
+
break
|
|
126
|
+
count[val] = count.get(val, 0) + 1
|
|
127
|
+
print(val)
|
|
128
|
+
|
|
129
|
+
print('consumed all: counts:', repr(count))
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
# Author
|
|
133
|
+
|
|
134
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
135
|
+
|
|
136
|
+
# Copyright and License
|
|
137
|
+
|
|
138
|
+
The MIT License (MIT)
|
|
139
|
+
|
|
140
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
__init__.py
|
|
4
|
+
priorityqueue.py
|
|
5
|
+
pyproject.toml
|
|
6
|
+
synopsis.py
|
|
7
|
+
./__init__.py
|
|
8
|
+
./priorityqueue.py
|
|
9
|
+
./synopsis.py
|
|
10
|
+
k3priorityqueue.egg-info/PKG-INFO
|
|
11
|
+
k3priorityqueue.egg-info/SOURCES.txt
|
|
12
|
+
k3priorityqueue.egg-info/dependency_links.txt
|
|
13
|
+
k3priorityqueue.egg-info/requires.txt
|
|
14
|
+
k3priorityqueue.egg-info/top_level.txt
|
|
15
|
+
test/test_doctest.py
|
|
16
|
+
test/test_k3priorityqueue.py
|
|
@@ -30,7 +30,7 @@ class Producer(object):
|
|
|
30
30
|
def __init__(self, producer_id, priority, iterable):
|
|
31
31
|
self.consumed = 0
|
|
32
32
|
self.iterable_lock = threading.RLock()
|
|
33
|
-
self.stat = {
|
|
33
|
+
self.stat = {"get": 0}
|
|
34
34
|
self.cmp_key = (0, 0)
|
|
35
35
|
|
|
36
36
|
self.producer_id = producer_id
|
|
@@ -38,22 +38,20 @@ class Producer(object):
|
|
|
38
38
|
self.set_iterable(iterable)
|
|
39
39
|
|
|
40
40
|
def get(self):
|
|
41
|
-
|
|
42
41
|
with self.iterable_lock:
|
|
43
42
|
try:
|
|
44
43
|
val = next(self.iterable)
|
|
45
|
-
self.stat[
|
|
44
|
+
self.stat["get"] += 1
|
|
46
45
|
self.consume()
|
|
47
46
|
return val
|
|
48
47
|
except StopIteration:
|
|
49
|
-
raise Empty(
|
|
48
|
+
raise Empty("no more item in " + str(self))
|
|
50
49
|
|
|
51
50
|
def set_priority(self, priority):
|
|
52
|
-
|
|
53
51
|
priority = float(priority)
|
|
54
52
|
|
|
55
53
|
if priority <= 0:
|
|
56
|
-
raise ValueError(
|
|
54
|
+
raise ValueError("priority can not be less or euqal 0: " + str(priority))
|
|
57
55
|
|
|
58
56
|
self.priority = priority
|
|
59
57
|
self.item_cost = default_priority / float(self.priority)
|
|
@@ -67,7 +65,7 @@ class Producer(object):
|
|
|
67
65
|
self.cmp_key = (self.consumed, self.item_cost)
|
|
68
66
|
|
|
69
67
|
def __str__(self):
|
|
70
|
-
return
|
|
68
|
+
return "[{producer_id}={priority} c={consumed}]".format(
|
|
71
69
|
producer_id=self.producer_id,
|
|
72
70
|
priority=self.priority,
|
|
73
71
|
consumed=self.consumed,
|
|
@@ -92,6 +90,7 @@ class PriorityQueue(object):
|
|
|
92
90
|
To re-enable a producer, call `PriorityQueue.add_producer()` with the same
|
|
93
91
|
`producer_id`.
|
|
94
92
|
"""
|
|
93
|
+
|
|
95
94
|
def __init__(self):
|
|
96
95
|
self.producer_by_id = {}
|
|
97
96
|
|
|
@@ -153,7 +152,6 @@ class PriorityQueue(object):
|
|
|
153
152
|
del self.producer_by_id[producer_id]
|
|
154
153
|
|
|
155
154
|
def _remove_from_heaps(self, producer):
|
|
156
|
-
|
|
157
155
|
try:
|
|
158
156
|
self.empty_heap.remove(producer)
|
|
159
157
|
except k3heap.NotFound:
|
|
@@ -166,22 +164,20 @@ class PriorityQueue(object):
|
|
|
166
164
|
|
|
167
165
|
def get(self):
|
|
168
166
|
"""
|
|
169
|
-
|
|
167
|
+
Returns an item.
|
|
170
168
|
"""
|
|
171
169
|
while True:
|
|
172
|
-
|
|
173
170
|
with self.heap_lock:
|
|
174
171
|
try:
|
|
175
172
|
p = self.consumable_heap.get()
|
|
176
173
|
except k3heap.Empty:
|
|
177
|
-
raise Empty(
|
|
174
|
+
raise Empty("no more queue has any item")
|
|
178
175
|
|
|
179
176
|
try:
|
|
180
177
|
# NOTE: if p.iterable blocks, everything is blocked
|
|
181
178
|
val = p.get()
|
|
182
179
|
|
|
183
180
|
except Empty:
|
|
184
|
-
|
|
185
181
|
self.consumable_heap.remove(p)
|
|
186
182
|
self.empty_heap.push(p)
|
|
187
183
|
|
|
@@ -197,4 +193,4 @@ class PriorityQueue(object):
|
|
|
197
193
|
for cq in self.producer_by_id.values():
|
|
198
194
|
qs.append(str(cq))
|
|
199
195
|
|
|
200
|
-
return
|
|
196
|
+
return " ".join(qs)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "k3priorityqueue"
|
|
7
|
+
version = "0.1.4"
|
|
8
|
+
description = "Priority queue with weighted producer support"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Zhang Yanpo", email = "drdr.xp@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["queue", "priority-queue", "producer", "weighted"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Software Development :: Libraries",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"k3heap",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/pykit3/k3priorityqueue"
|
|
33
|
+
Documentation = "https://k3priorityqueue.readthedocs.io"
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = [
|
|
37
|
+
"pytest>=7.0",
|
|
38
|
+
"ruff",
|
|
39
|
+
"coverage",
|
|
40
|
+
"k3ut",
|
|
41
|
+
"k3thread",
|
|
42
|
+
]
|
|
43
|
+
publish = [
|
|
44
|
+
"build",
|
|
45
|
+
"twine",
|
|
46
|
+
"pk3",
|
|
47
|
+
]
|
|
48
|
+
docs = [
|
|
49
|
+
"mkdocs>=1.5",
|
|
50
|
+
"mkdocs-material>=9.0",
|
|
51
|
+
"mkdocstrings[python]>=0.24",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[tool.setuptools]
|
|
55
|
+
packages = ["k3priorityqueue"]
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.package-dir]
|
|
58
|
+
k3priorityqueue = "."
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 120
|
|
@@ -16,14 +16,14 @@ for _ in range(12):
|
|
|
16
16
|
count[val] = count.get(val, 0) + 1
|
|
17
17
|
print(val)
|
|
18
18
|
|
|
19
|
-
print(
|
|
19
|
+
print("respect priority ratio: counts:", repr(count))
|
|
20
20
|
|
|
21
21
|
while True:
|
|
22
22
|
try:
|
|
23
23
|
val = pq.get()
|
|
24
|
-
except k3priorityqueue.Empty
|
|
24
|
+
except k3priorityqueue.Empty:
|
|
25
25
|
break
|
|
26
26
|
count[val] = count.get(val, 0) + 1
|
|
27
27
|
print(val)
|
|
28
28
|
|
|
29
|
-
print(
|
|
29
|
+
print("consumed all: counts:", repr(count))
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
import k3priorityqueue
|
|
5
|
+
import k3thread
|
|
6
|
+
import k3ut
|
|
7
|
+
|
|
8
|
+
dd = k3ut.dd
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestConsumedQueue(unittest.TestCase):
|
|
12
|
+
def test_init(self):
|
|
13
|
+
cq = k3priorityqueue.Producer(1, 1, [])
|
|
14
|
+
self.assertEqual(1, cq.priority)
|
|
15
|
+
self.assertEqual(0, cq.consumed)
|
|
16
|
+
self.assertEqual(k3priorityqueue.default_priority / cq.priority, cq.item_cost)
|
|
17
|
+
|
|
18
|
+
def test_priority(self):
|
|
19
|
+
self.assertRaises(ValueError, k3priorityqueue.Producer, 1, 0, [])
|
|
20
|
+
self.assertRaises(ValueError, k3priorityqueue.Producer, 1, -1, [])
|
|
21
|
+
self.assertRaises(ValueError, k3priorityqueue.Producer, 1, "", [])
|
|
22
|
+
|
|
23
|
+
def test_consumed(self):
|
|
24
|
+
a = k3priorityqueue.Producer(1, 1, [1, 2])
|
|
25
|
+
b = k3priorityqueue.Producer(1, 10, range(20))
|
|
26
|
+
|
|
27
|
+
self.assertEqual(1, a.get())
|
|
28
|
+
self.assertEqual(2, a.get())
|
|
29
|
+
self.assertRaises(k3priorityqueue.Empty, a.get)
|
|
30
|
+
|
|
31
|
+
for i in range(20):
|
|
32
|
+
b.get()
|
|
33
|
+
|
|
34
|
+
self.assertEqual(a.consumed, b.consumed)
|
|
35
|
+
|
|
36
|
+
def test_lt_init(self):
|
|
37
|
+
a = k3priorityqueue.Producer(1, 1, [1, 2])
|
|
38
|
+
b = k3priorityqueue.Producer(1, 1, [1, 2])
|
|
39
|
+
|
|
40
|
+
self.assertFalse(a < b, "both empty")
|
|
41
|
+
self.assertFalse(b < a, "both empty")
|
|
42
|
+
|
|
43
|
+
a.get()
|
|
44
|
+
b.get()
|
|
45
|
+
|
|
46
|
+
self.assertFalse(a < b, "both empty")
|
|
47
|
+
self.assertFalse(b < a, "both empty")
|
|
48
|
+
|
|
49
|
+
def test_lt(self):
|
|
50
|
+
a = k3priorityqueue.Producer(1, 1, range(100))
|
|
51
|
+
b = k3priorityqueue.Producer(1, 10, range(100))
|
|
52
|
+
|
|
53
|
+
# 0 0, but b has smaller item_cost
|
|
54
|
+
self.assertFalse(a < b, "b has higher priority")
|
|
55
|
+
self.assertTrue(b < a, "b has higher priority")
|
|
56
|
+
|
|
57
|
+
# 0 0.1
|
|
58
|
+
b.get()
|
|
59
|
+
self.assertTrue(a < b, "b consumed 1")
|
|
60
|
+
self.assertFalse(b < a, "b consumed 1")
|
|
61
|
+
|
|
62
|
+
# 1 0.1
|
|
63
|
+
a.get()
|
|
64
|
+
self.assertFalse(a < b, "a consumed 1")
|
|
65
|
+
self.assertTrue(b < a, "a consumed 1")
|
|
66
|
+
|
|
67
|
+
# 1 0.2
|
|
68
|
+
b.get()
|
|
69
|
+
self.assertFalse(a < b, "a b consumed 1")
|
|
70
|
+
self.assertTrue(b < a, "a b consumed 1")
|
|
71
|
+
|
|
72
|
+
# 1 1
|
|
73
|
+
for _ in range(8):
|
|
74
|
+
b.get()
|
|
75
|
+
self.assertFalse(a < b, "a b consumed 1")
|
|
76
|
+
self.assertTrue(b < a, "a consume 1 b consumed 10")
|
|
77
|
+
|
|
78
|
+
# 1 1.1
|
|
79
|
+
b.get()
|
|
80
|
+
self.assertTrue(a < b, "a b consumed 1")
|
|
81
|
+
self.assertFalse(b < a, "a b consumed 1")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class TestPriorityQueue(unittest.TestCase):
|
|
85
|
+
def test_get(self):
|
|
86
|
+
producers = (
|
|
87
|
+
# id, priority, iterable
|
|
88
|
+
(1, 1, [1] * 10),
|
|
89
|
+
(2, 2, [2] * 10),
|
|
90
|
+
(3, 3, [3] * 10),
|
|
91
|
+
)
|
|
92
|
+
expected = [
|
|
93
|
+
3, # .3 0 0.0
|
|
94
|
+
2, # .3 .5 0.0
|
|
95
|
+
1, # .3 .5 1.0
|
|
96
|
+
3, # .6 .5 1.0
|
|
97
|
+
2, # .6 1.0 1.0
|
|
98
|
+
3, # 1.0 1.0 1.0
|
|
99
|
+
3, # 1.3 1.0 1.0
|
|
100
|
+
2, # 1.3 1.5 1.0
|
|
101
|
+
1, # 1.3 1.5 2.0
|
|
102
|
+
3, # 1.6 1.5 2.0
|
|
103
|
+
2, # 1.6 2.0 2.0
|
|
104
|
+
3, # 2.0 2.0 2.0
|
|
105
|
+
]
|
|
106
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
107
|
+
for pid, prio, itr in producers:
|
|
108
|
+
pq.add_producer(pid, prio, itr)
|
|
109
|
+
|
|
110
|
+
dd(pq)
|
|
111
|
+
rst = []
|
|
112
|
+
for _ in expected:
|
|
113
|
+
val = pq.get()
|
|
114
|
+
rst.append(val)
|
|
115
|
+
self.assertEqual(expected, rst)
|
|
116
|
+
|
|
117
|
+
def test_add_queue(self):
|
|
118
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
119
|
+
pq.add_producer(1, 1, [1, 1])
|
|
120
|
+
self.assertEqual(1, pq.get())
|
|
121
|
+
|
|
122
|
+
# re-add should update iterable
|
|
123
|
+
pq.add_producer(1, 1, [2, 2])
|
|
124
|
+
self.assertEqual(2, pq.get())
|
|
125
|
+
|
|
126
|
+
# new queue with higher priority comes first
|
|
127
|
+
pq.add_producer(2, 10, [10, 10])
|
|
128
|
+
self.assertEqual(10, pq.get())
|
|
129
|
+
|
|
130
|
+
def test_add_queue_update_priority(self):
|
|
131
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
132
|
+
|
|
133
|
+
pq.add_producer(1, 1, [1, 1, 1])
|
|
134
|
+
self.assertEqual(1, pq.get())
|
|
135
|
+
|
|
136
|
+
pq.add_producer(2, 2, [2, 2, 2])
|
|
137
|
+
self.assertEqual(2, pq.get())
|
|
138
|
+
self.assertEqual(2, pq.get())
|
|
139
|
+
|
|
140
|
+
# re-add should update priority, iterable and adjust heap
|
|
141
|
+
pq.add_producer(1, 10, [10, 10, 10])
|
|
142
|
+
dd(pq)
|
|
143
|
+
dd(pq.consumable_heap)
|
|
144
|
+
|
|
145
|
+
self.assertEqual(10, pq.get())
|
|
146
|
+
|
|
147
|
+
def test_remove_queue(self):
|
|
148
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
149
|
+
pq.add_producer(1, 1, [1, 1])
|
|
150
|
+
pq.remove_producer(1)
|
|
151
|
+
|
|
152
|
+
self.assertRaises(k3priorityqueue.Empty, pq.get)
|
|
153
|
+
pq.add_producer(1, 1, [1, 1])
|
|
154
|
+
pq.add_producer(10, 10, [10, 10])
|
|
155
|
+
self.assertEqual(10, pq.get())
|
|
156
|
+
|
|
157
|
+
pq.remove_producer(10)
|
|
158
|
+
self.assertEqual(1, pq.get())
|
|
159
|
+
|
|
160
|
+
def test_remove_queue_inexistent(self):
|
|
161
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
162
|
+
self.assertRaises(KeyError, pq.remove_producer, 1)
|
|
163
|
+
pq.remove_producer(1, ignore_not_found=True)
|
|
164
|
+
|
|
165
|
+
def test_bench(self):
|
|
166
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
167
|
+
|
|
168
|
+
ntimes = 10240
|
|
169
|
+
nq = 1024
|
|
170
|
+
n_thread = 3
|
|
171
|
+
ths = []
|
|
172
|
+
|
|
173
|
+
def worker():
|
|
174
|
+
for _ in range(ntimes):
|
|
175
|
+
pq.get()
|
|
176
|
+
|
|
177
|
+
for i in range(1, nq + 1):
|
|
178
|
+
pq.add_producer(i, i, yield_forever())
|
|
179
|
+
|
|
180
|
+
with k3ut.Timer() as t:
|
|
181
|
+
for i in range(n_thread):
|
|
182
|
+
th = k3thread.daemon(worker)
|
|
183
|
+
ths.append(th)
|
|
184
|
+
|
|
185
|
+
for th in ths:
|
|
186
|
+
th.join()
|
|
187
|
+
|
|
188
|
+
us_per_call = t.spent() / ntimes / n_thread * 1000 * 1000
|
|
189
|
+
dd(us_per_call, "us/call")
|
|
190
|
+
|
|
191
|
+
self.assertLess(us_per_call, 100)
|
|
192
|
+
|
|
193
|
+
def test_concurrent(self):
|
|
194
|
+
pq = k3priorityqueue.PriorityQueue()
|
|
195
|
+
ntimes = 10240
|
|
196
|
+
nq = 3
|
|
197
|
+
n_thread = 3
|
|
198
|
+
ths = []
|
|
199
|
+
|
|
200
|
+
def worker():
|
|
201
|
+
for _ in range(ntimes):
|
|
202
|
+
pq.get()
|
|
203
|
+
|
|
204
|
+
for i in range(1, nq + 1):
|
|
205
|
+
pq.add_producer(i, i, yield_forever())
|
|
206
|
+
|
|
207
|
+
for i in range(n_thread):
|
|
208
|
+
th = k3thread.daemon(worker)
|
|
209
|
+
ths.append(th)
|
|
210
|
+
|
|
211
|
+
for th in ths:
|
|
212
|
+
th.join()
|
|
213
|
+
|
|
214
|
+
consumed = []
|
|
215
|
+
got = 0
|
|
216
|
+
for i in range(1, nq + 1):
|
|
217
|
+
q = pq.producer_by_id[i]
|
|
218
|
+
consumed.append(q.consumed)
|
|
219
|
+
dd("get:", q.stat)
|
|
220
|
+
got += q.stat["get"]
|
|
221
|
+
|
|
222
|
+
self.assertEqual(ntimes * n_thread, got)
|
|
223
|
+
|
|
224
|
+
dd("consumed:", consumed)
|
|
225
|
+
self.assertAlmostEqual(consumed[0], consumed[1])
|
|
226
|
+
self.assertAlmostEqual(consumed[1], consumed[2])
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def yield_forever():
|
|
230
|
+
i = random.randint(1, 1000000)
|
|
231
|
+
while True:
|
|
232
|
+
i += 1
|
|
233
|
+
yield (i * 2654435769) & 0xFFFFFFFF
|
k3priorityqueue-0.1.2/PKG-INFO
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: k3priorityqueue
|
|
3
|
-
Version: 0.1.2
|
|
4
|
-
Summary: priorityQueue is a queue with priority support
|
|
5
|
-
Home-page: https://github.com/pykit3/k3priorityqueue
|
|
6
|
-
Author: Zhang Yanpo
|
|
7
|
-
Author-email: drdr.xp@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: # k3priorityqueue
|
|
10
|
-
|
|
11
|
-
[](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)
|
|
12
|
-
[](https://travis-ci.com/pykit3/k3priorityqueue)
|
|
13
|
-
[](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)
|
|
14
|
-
[](https://pypi.org/project/k3priorityqueue)
|
|
15
|
-
|
|
16
|
-
priorityQueue is a queue with priority support
|
|
17
|
-
|
|
18
|
-
k3priorityqueue is a component of [pykit3] project: a python3 toolkit set.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
PriorityQueue is a queue with priority support:
|
|
22
|
-
|
|
23
|
-
The numbers of items it pops from each producer matches exactly the ratio of their priority:
|
|
24
|
-
If the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long
|
|
25
|
-
enough, it is expected that the number of items popped from A, B and C are
|
|
26
|
-
1:3:7.
|
|
27
|
-
|
|
28
|
-
import k3priorityqueue
|
|
29
|
-
|
|
30
|
-
producers = (
|
|
31
|
-
# id, priority, iterable
|
|
32
|
-
(1, 1, [1] * 10),
|
|
33
|
-
(2, 2, [2] * 10),
|
|
34
|
-
(3, 3, [3] * 10),
|
|
35
|
-
)
|
|
36
|
-
pq = k3priorityqueue.PriorityQueue()
|
|
37
|
-
for pid, prio, itr in producers:
|
|
38
|
-
pq.add_producer(pid, prio, itr)
|
|
39
|
-
|
|
40
|
-
count = {}
|
|
41
|
-
for _ in range(12):
|
|
42
|
-
val = pq.get()
|
|
43
|
-
count[val] = count.get(val, 0) + 1
|
|
44
|
-
print(val)
|
|
45
|
-
|
|
46
|
-
print('respect priority ratio: counts:', repr(count))
|
|
47
|
-
|
|
48
|
-
while True:
|
|
49
|
-
try:
|
|
50
|
-
val = pq.get()
|
|
51
|
-
except k3priorityqueue.Empty as e:
|
|
52
|
-
break
|
|
53
|
-
count[val] = count.get(val, 0) + 1
|
|
54
|
-
print(val)
|
|
55
|
-
|
|
56
|
-
print('consumed all: counts:', repr(count))
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# Install
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
pip install k3priorityqueue
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
# Synopsis
|
|
68
|
-
|
|
69
|
-
```python
|
|
70
|
-
|
|
71
|
-
import k3priorityqueue
|
|
72
|
-
|
|
73
|
-
producers = (
|
|
74
|
-
# id, priority, iterable
|
|
75
|
-
(1, 1, [1] * 10),
|
|
76
|
-
(2, 2, [2] * 10),
|
|
77
|
-
(3, 3, [3] * 10),
|
|
78
|
-
)
|
|
79
|
-
pq = k3priorityqueue.PriorityQueue()
|
|
80
|
-
for pid, prio, itr in producers:
|
|
81
|
-
pq.add_producer(pid, prio, itr)
|
|
82
|
-
|
|
83
|
-
count = {}
|
|
84
|
-
for _ in range(12):
|
|
85
|
-
val = pq.get()
|
|
86
|
-
count[val] = count.get(val, 0) + 1
|
|
87
|
-
print(val)
|
|
88
|
-
|
|
89
|
-
print('respect priority ratio: counts:', repr(count))
|
|
90
|
-
|
|
91
|
-
while True:
|
|
92
|
-
try:
|
|
93
|
-
val = pq.get()
|
|
94
|
-
except k3priorityqueue.Empty as e:
|
|
95
|
-
break
|
|
96
|
-
count[val] = count.get(val, 0) + 1
|
|
97
|
-
print(val)
|
|
98
|
-
|
|
99
|
-
print('consumed all: counts:', repr(count))
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
# Author
|
|
103
|
-
|
|
104
|
-
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
105
|
-
|
|
106
|
-
# Copyright and License
|
|
107
|
-
|
|
108
|
-
The MIT License (MIT)
|
|
109
|
-
|
|
110
|
-
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
[pykit3]: https://github.com/pykit3
|
|
114
|
-
Keywords: python,priorityqueue
|
|
115
|
-
Platform: UNKNOWN
|
|
116
|
-
Classifier: Development Status :: 4 - Beta
|
|
117
|
-
Classifier: Intended Audience :: Developers
|
|
118
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
119
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
120
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
121
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
122
|
-
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
123
|
-
Requires-Python: >=3.0
|
|
124
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# DO NOT EDIT!!! built with `python _building/build_setup.py`
|
|
2
|
-
import setuptools
|
|
3
|
-
setuptools.setup(
|
|
4
|
-
name="k3priorityqueue",
|
|
5
|
-
packages=["k3priorityqueue"],
|
|
6
|
-
version="0.1.2",
|
|
7
|
-
license='MIT',
|
|
8
|
-
description='priorityQueue is a queue with priority support',
|
|
9
|
-
long_description="# k3priorityqueue\n\n[](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)\n[](https://travis-ci.com/pykit3/k3priorityqueue)\n[](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)\n[](https://pypi.org/project/k3priorityqueue)\n\npriorityQueue is a queue with priority support\n\nk3priorityqueue is a component of [pykit3] project: a python3 toolkit set.\n\n\nPriorityQueue is a queue with priority support:\n\nThe numbers of items it pops from each producer matches exactly the ratio of their priority:\nIf the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long\nenough, it is expected that the number of items popped from A, B and C are\n1:3:7.\n\nimport k3priorityqueue\n\nproducers = (\n # id, priority, iterable\n (1, 1, [1] * 10),\n (2, 2, [2] * 10),\n (3, 3, [3] * 10),\n)\npq = k3priorityqueue.PriorityQueue()\nfor pid, prio, itr in producers:\n pq.add_producer(pid, prio, itr)\n\ncount = {}\nfor _ in range(12):\n val = pq.get()\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('respect priority ratio: counts:', repr(count))\n\nwhile True:\n try:\n val = pq.get()\n except k3priorityqueue.Empty as e:\n break\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('consumed all: counts:', repr(count))\n\n\n\n\n# Install\n\n```\npip install k3priorityqueue\n```\n\n# Synopsis\n\n```python\n\nimport k3priorityqueue\n\nproducers = (\n # id, priority, iterable\n (1, 1, [1] * 10),\n (2, 2, [2] * 10),\n (3, 3, [3] * 10),\n)\npq = k3priorityqueue.PriorityQueue()\nfor pid, prio, itr in producers:\n pq.add_producer(pid, prio, itr)\n\ncount = {}\nfor _ in range(12):\n val = pq.get()\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('respect priority ratio: counts:', repr(count))\n\nwhile True:\n try:\n val = pq.get()\n except k3priorityqueue.Empty as e:\n break\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('consumed all: counts:', repr(count))\n```\n\n# Author\n\nZhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n# Copyright and License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n\n[pykit3]: https://github.com/pykit3",
|
|
10
|
-
long_description_content_type="text/markdown",
|
|
11
|
-
author='Zhang Yanpo',
|
|
12
|
-
author_email='drdr.xp@gmail.com',
|
|
13
|
-
url='https://github.com/pykit3/k3priorityqueue',
|
|
14
|
-
keywords=['python', 'priorityqueue'],
|
|
15
|
-
python_requires='>=3.0',
|
|
16
|
-
|
|
17
|
-
install_requires=['k3ut>=0.1.15,<0.2', 'k3heap>=0.1.5,<0.2', 'k3thread>=0.1.0,<0.2'],
|
|
18
|
-
classifiers=[
|
|
19
|
-
'Development Status :: 4 - Beta',
|
|
20
|
-
'Intended Audience :: Developers',
|
|
21
|
-
'Topic :: Software Development :: Libraries',
|
|
22
|
-
] + ['Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: Implementation :: PyPy'],
|
|
23
|
-
)
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: k3priorityqueue
|
|
3
|
-
Version: 0.1.2
|
|
4
|
-
Summary: priorityQueue is a queue with priority support
|
|
5
|
-
Home-page: https://github.com/pykit3/k3priorityqueue
|
|
6
|
-
Author: Zhang Yanpo
|
|
7
|
-
Author-email: drdr.xp@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: # k3priorityqueue
|
|
10
|
-
|
|
11
|
-
[](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)
|
|
12
|
-
[](https://travis-ci.com/pykit3/k3priorityqueue)
|
|
13
|
-
[](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)
|
|
14
|
-
[](https://pypi.org/project/k3priorityqueue)
|
|
15
|
-
|
|
16
|
-
priorityQueue is a queue with priority support
|
|
17
|
-
|
|
18
|
-
k3priorityqueue is a component of [pykit3] project: a python3 toolkit set.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
PriorityQueue is a queue with priority support:
|
|
22
|
-
|
|
23
|
-
The numbers of items it pops from each producer matches exactly the ratio of their priority:
|
|
24
|
-
If the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long
|
|
25
|
-
enough, it is expected that the number of items popped from A, B and C are
|
|
26
|
-
1:3:7.
|
|
27
|
-
|
|
28
|
-
import k3priorityqueue
|
|
29
|
-
|
|
30
|
-
producers = (
|
|
31
|
-
# id, priority, iterable
|
|
32
|
-
(1, 1, [1] * 10),
|
|
33
|
-
(2, 2, [2] * 10),
|
|
34
|
-
(3, 3, [3] * 10),
|
|
35
|
-
)
|
|
36
|
-
pq = k3priorityqueue.PriorityQueue()
|
|
37
|
-
for pid, prio, itr in producers:
|
|
38
|
-
pq.add_producer(pid, prio, itr)
|
|
39
|
-
|
|
40
|
-
count = {}
|
|
41
|
-
for _ in range(12):
|
|
42
|
-
val = pq.get()
|
|
43
|
-
count[val] = count.get(val, 0) + 1
|
|
44
|
-
print(val)
|
|
45
|
-
|
|
46
|
-
print('respect priority ratio: counts:', repr(count))
|
|
47
|
-
|
|
48
|
-
while True:
|
|
49
|
-
try:
|
|
50
|
-
val = pq.get()
|
|
51
|
-
except k3priorityqueue.Empty as e:
|
|
52
|
-
break
|
|
53
|
-
count[val] = count.get(val, 0) + 1
|
|
54
|
-
print(val)
|
|
55
|
-
|
|
56
|
-
print('consumed all: counts:', repr(count))
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
# Install
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
pip install k3priorityqueue
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
# Synopsis
|
|
68
|
-
|
|
69
|
-
```python
|
|
70
|
-
|
|
71
|
-
import k3priorityqueue
|
|
72
|
-
|
|
73
|
-
producers = (
|
|
74
|
-
# id, priority, iterable
|
|
75
|
-
(1, 1, [1] * 10),
|
|
76
|
-
(2, 2, [2] * 10),
|
|
77
|
-
(3, 3, [3] * 10),
|
|
78
|
-
)
|
|
79
|
-
pq = k3priorityqueue.PriorityQueue()
|
|
80
|
-
for pid, prio, itr in producers:
|
|
81
|
-
pq.add_producer(pid, prio, itr)
|
|
82
|
-
|
|
83
|
-
count = {}
|
|
84
|
-
for _ in range(12):
|
|
85
|
-
val = pq.get()
|
|
86
|
-
count[val] = count.get(val, 0) + 1
|
|
87
|
-
print(val)
|
|
88
|
-
|
|
89
|
-
print('respect priority ratio: counts:', repr(count))
|
|
90
|
-
|
|
91
|
-
while True:
|
|
92
|
-
try:
|
|
93
|
-
val = pq.get()
|
|
94
|
-
except k3priorityqueue.Empty as e:
|
|
95
|
-
break
|
|
96
|
-
count[val] = count.get(val, 0) + 1
|
|
97
|
-
print(val)
|
|
98
|
-
|
|
99
|
-
print('consumed all: counts:', repr(count))
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
# Author
|
|
103
|
-
|
|
104
|
-
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
105
|
-
|
|
106
|
-
# Copyright and License
|
|
107
|
-
|
|
108
|
-
The MIT License (MIT)
|
|
109
|
-
|
|
110
|
-
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
[pykit3]: https://github.com/pykit3
|
|
114
|
-
Keywords: python,priorityqueue
|
|
115
|
-
Platform: UNKNOWN
|
|
116
|
-
Classifier: Development Status :: 4 - Beta
|
|
117
|
-
Classifier: Intended Audience :: Developers
|
|
118
|
-
Classifier: Topic :: Software Development :: Libraries
|
|
119
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
120
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
121
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
122
|
-
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
123
|
-
Requires-Python: >=3.0
|
|
124
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
setup.py
|
|
2
|
-
k3priorityqueue/__init__.py
|
|
3
|
-
k3priorityqueue/priorityqueue.py
|
|
4
|
-
k3priorityqueue/setup.py
|
|
5
|
-
k3priorityqueue/synopsis.py
|
|
6
|
-
k3priorityqueue.egg-info/PKG-INFO
|
|
7
|
-
k3priorityqueue.egg-info/SOURCES.txt
|
|
8
|
-
k3priorityqueue.egg-info/dependency_links.txt
|
|
9
|
-
k3priorityqueue.egg-info/requires.txt
|
|
10
|
-
k3priorityqueue.egg-info/top_level.txt
|
k3priorityqueue-0.1.2/setup.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# DO NOT EDIT!!! built with `python _building/build_setup.py`
|
|
2
|
-
import setuptools
|
|
3
|
-
setuptools.setup(
|
|
4
|
-
name="k3priorityqueue",
|
|
5
|
-
packages=["k3priorityqueue"],
|
|
6
|
-
version="0.1.2",
|
|
7
|
-
license='MIT',
|
|
8
|
-
description='priorityQueue is a queue with priority support',
|
|
9
|
-
long_description="# k3priorityqueue\n\n[](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)\n[](https://travis-ci.com/pykit3/k3priorityqueue)\n[](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)\n[](https://pypi.org/project/k3priorityqueue)\n\npriorityQueue is a queue with priority support\n\nk3priorityqueue is a component of [pykit3] project: a python3 toolkit set.\n\n\nPriorityQueue is a queue with priority support:\n\nThe numbers of items it pops from each producer matches exactly the ratio of their priority:\nIf the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long\nenough, it is expected that the number of items popped from A, B and C are\n1:3:7.\n\nimport k3priorityqueue\n\nproducers = (\n # id, priority, iterable\n (1, 1, [1] * 10),\n (2, 2, [2] * 10),\n (3, 3, [3] * 10),\n)\npq = k3priorityqueue.PriorityQueue()\nfor pid, prio, itr in producers:\n pq.add_producer(pid, prio, itr)\n\ncount = {}\nfor _ in range(12):\n val = pq.get()\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('respect priority ratio: counts:', repr(count))\n\nwhile True:\n try:\n val = pq.get()\n except k3priorityqueue.Empty as e:\n break\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('consumed all: counts:', repr(count))\n\n\n\n\n# Install\n\n```\npip install k3priorityqueue\n```\n\n# Synopsis\n\n```python\n\nimport k3priorityqueue\n\nproducers = (\n # id, priority, iterable\n (1, 1, [1] * 10),\n (2, 2, [2] * 10),\n (3, 3, [3] * 10),\n)\npq = k3priorityqueue.PriorityQueue()\nfor pid, prio, itr in producers:\n pq.add_producer(pid, prio, itr)\n\ncount = {}\nfor _ in range(12):\n val = pq.get()\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('respect priority ratio: counts:', repr(count))\n\nwhile True:\n try:\n val = pq.get()\n except k3priorityqueue.Empty as e:\n break\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('consumed all: counts:', repr(count))\n```\n\n# Author\n\nZhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n# Copyright and License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n\n[pykit3]: https://github.com/pykit3",
|
|
10
|
-
long_description_content_type="text/markdown",
|
|
11
|
-
author='Zhang Yanpo',
|
|
12
|
-
author_email='drdr.xp@gmail.com',
|
|
13
|
-
url='https://github.com/pykit3/k3priorityqueue',
|
|
14
|
-
keywords=['python', 'priorityqueue'],
|
|
15
|
-
python_requires='>=3.0',
|
|
16
|
-
|
|
17
|
-
install_requires=['k3ut>=0.1.15,<0.2', 'k3heap>=0.1.5,<0.2', 'k3thread>=0.1.0,<0.2'],
|
|
18
|
-
classifiers=[
|
|
19
|
-
'Development Status :: 4 - Beta',
|
|
20
|
-
'Intended Audience :: Developers',
|
|
21
|
-
'Topic :: Software Development :: Libraries',
|
|
22
|
-
] + ['Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: Implementation :: PyPy'],
|
|
23
|
-
)
|
{k3priorityqueue-0.1.2 → k3priorityqueue-0.1.4}/k3priorityqueue.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|