depq 0.6 → 0.7
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.
- checksums.yaml +7 -0
- data/README +27 -27
- data/lib/depq.rb +66 -43
- data/sample/dhondt.rb +53 -0
- data/test/test-depq.rb +35 -31
- metadata +14 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e79a116c9cd6b58578bf23c9100e7bc0f5e19a21
|
4
|
+
data.tar.gz: b4a2db49fd3317bd8db9e9b523a032f462ed7c76
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c8d68e0287f4057d239f18ff810f9aea3f1f0c518e0c9f4a7d340e528a31d599a1a7c1918d65941232ff86ed4742eb8c02472fd3e65e006866fba18f5a2c1ee
|
7
|
+
data.tar.gz: 592cee5adb6c096fa464e4725d43d51a5bb53b8bdd179b8c51b6d6dc01a39471ea46a6cb02d85ddc8b2b9345816836e34d3e65ec7009836b080bba7a769a6489
|
data/README
CHANGED
@@ -8,9 +8,9 @@ depq is double-ended stable priority queue with priority update operation implem
|
|
8
8
|
* priority - you can get a value with minimum priority
|
9
9
|
* double-ended - you can get a value with maximum priority too
|
10
10
|
* stable - you will get the value inserted first with minimum/maximum priority
|
11
|
-
* priority update - usable for Dijkstra's shortest path algorithm and various graph algorithms
|
11
|
+
* priority update - you can change the priority of inserted values (usable for Dijkstra's shortest path algorithm and various graph algorithms)
|
12
12
|
* implicit heap - compact heap representation using array. most operations are O(log n) at worst
|
13
|
-
*
|
13
|
+
* several utility methods: nlargest, nsmallest, merge, astar_search
|
14
14
|
|
15
15
|
== Install
|
16
16
|
|
@@ -18,12 +18,8 @@ depq is double-ended stable priority queue with priority update operation implem
|
|
18
18
|
|
19
19
|
== Links
|
20
20
|
|
21
|
-
* ((<reference manual|URL:http://depq.rubyforge.org/rdoc/classes/Depq.html>))
|
22
|
-
* ((<home page on rubyforge|URL:http://depq.rubyforge.org/>))
|
23
|
-
* ((<project info on rubyforge|URL:http://rubyforge.org/projects/depq/>))
|
24
|
-
* ((<depq on rubygems.org|URL:http://rubygems.org/gems/depq>))
|
25
21
|
* ((<source repository on github|URL:http://github.com/akr/depq>))
|
26
|
-
* ((<
|
22
|
+
* ((<depq on rubygems.org|URL:http://rubygems.org/gems/depq>))
|
27
23
|
|
28
24
|
== Introduction
|
29
25
|
|
@@ -182,26 +178,30 @@ Tanaka Akira <akr@fsij.org>
|
|
182
178
|
== License
|
183
179
|
|
184
180
|
Redistribution and use in source and binary forms, with or without
|
185
|
-
modification, are permitted provided that the following conditions
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
OF
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
OF
|
181
|
+
modification, are permitted provided that the following conditions
|
182
|
+
are met:
|
183
|
+
|
184
|
+
1. Redistributions of source code must retain the above copyright
|
185
|
+
notice, this list of conditions and the following disclaimer.
|
186
|
+
2. Redistributions in binary form must reproduce the above
|
187
|
+
copyright notice, this list of conditions and the following
|
188
|
+
disclaimer in the documentation and/or other materials provided
|
189
|
+
with the distribution.
|
190
|
+
3. The name of the author may not be used to endorse or promote
|
191
|
+
products derived from this software without specific prior
|
192
|
+
written permission.
|
193
|
+
|
194
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
195
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
196
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
197
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
198
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
199
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
200
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
201
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
202
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
203
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
204
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
205
205
|
|
206
206
|
(The modified BSD licence)
|
207
207
|
|
data/lib/depq.rb
CHANGED
@@ -3,26 +3,30 @@
|
|
3
3
|
# Copyright (C) 2009-2011 Tanaka Akira <akr@fsij.org>
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
6
|
-
# modification, are permitted provided that the following conditions
|
6
|
+
# modification, are permitted provided that the following conditions
|
7
|
+
# are met:
|
7
8
|
#
|
8
|
-
# 1. Redistributions of source code must retain the above copyright
|
9
|
-
# list of conditions and the following disclaimer.
|
10
|
-
# 2. Redistributions in binary form must reproduce the above
|
11
|
-
# this list of conditions and the following
|
12
|
-
# and/or other materials provided
|
13
|
-
#
|
14
|
-
#
|
9
|
+
# 1. Redistributions of source code must retain the above copyright
|
10
|
+
# notice, this list of conditions and the following disclaimer.
|
11
|
+
# 2. Redistributions in binary form must reproduce the above
|
12
|
+
# copyright notice, this list of conditions and the following
|
13
|
+
# disclaimer in the documentation and/or other materials provided
|
14
|
+
# with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote
|
16
|
+
# products derived from this software without specific prior
|
17
|
+
# written permission.
|
15
18
|
#
|
16
|
-
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
17
|
-
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
-
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
-
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# IN
|
25
|
-
# OF
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
20
|
+
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
23
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
25
|
+
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
27
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
28
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
29
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
30
|
|
27
31
|
# = Depq - Double-Ended Priority Queue
|
28
32
|
#
|
@@ -295,7 +299,7 @@ class Depq
|
|
295
299
|
def priority
|
296
300
|
if in_queue?
|
297
301
|
q = depq_or_subpriority()
|
298
|
-
priority,
|
302
|
+
priority, _subpriority = q.send(:internal_get_priority, self)
|
299
303
|
priority
|
300
304
|
else
|
301
305
|
index_or_priority()
|
@@ -306,7 +310,7 @@ class Depq
|
|
306
310
|
def subpriority
|
307
311
|
if in_queue?
|
308
312
|
q = depq_or_subpriority()
|
309
|
-
|
313
|
+
_priority, subpriority = q.send(:internal_get_priority, self)
|
310
314
|
subpriority
|
311
315
|
else
|
312
316
|
depq_or_subpriority()
|
@@ -441,6 +445,26 @@ class Depq
|
|
441
445
|
ARY_SLICE_SIZE = 3
|
442
446
|
# :startdoc:
|
443
447
|
|
448
|
+
def get_entry_ps(i)
|
449
|
+
get_entry(i).values_at(1, 2)
|
450
|
+
end
|
451
|
+
private :get_entry_ps
|
452
|
+
|
453
|
+
def get_entry_e(i)
|
454
|
+
get_entry(i)[0]
|
455
|
+
end
|
456
|
+
private :get_entry_e
|
457
|
+
|
458
|
+
def get_entry_p(i)
|
459
|
+
get_entry(i)[1]
|
460
|
+
end
|
461
|
+
private :get_entry_p
|
462
|
+
|
463
|
+
def get_entry_s(i)
|
464
|
+
get_entry(i)[2]
|
465
|
+
end
|
466
|
+
private :get_entry_s
|
467
|
+
|
444
468
|
def get_entry(i)
|
445
469
|
locator = @ary[i*ARY_SLICE_SIZE+0]
|
446
470
|
priority = @ary[i*ARY_SLICE_SIZE+1]
|
@@ -535,7 +559,7 @@ class Depq
|
|
535
559
|
|
536
560
|
def check_locator(loc)
|
537
561
|
if !self.equal?(loc.depq) ||
|
538
|
-
!
|
562
|
+
!get_entry_e(loc.send(:index)).equal?(loc)
|
539
563
|
raise ArgumentError, "unexpected locator"
|
540
564
|
end
|
541
565
|
end
|
@@ -689,7 +713,7 @@ class Depq
|
|
689
713
|
|
690
714
|
def internal_get_priority(loc)
|
691
715
|
check_locator(loc)
|
692
|
-
|
716
|
+
priority, subpriority = get_entry_ps(loc.send(:index))
|
693
717
|
[priority, subpriority]
|
694
718
|
end
|
695
719
|
private :internal_get_priority
|
@@ -968,7 +992,7 @@ class Depq
|
|
968
992
|
check_locator(loc)
|
969
993
|
index = loc.send(:index)
|
970
994
|
if @heapsize <= index
|
971
|
-
|
995
|
+
priority, subpriority = get_entry_ps(index)
|
972
996
|
last = self.size - 1
|
973
997
|
if index != last
|
974
998
|
loc2, priority2, subpriority2 = get_entry(last)
|
@@ -1128,7 +1152,7 @@ class Depq
|
|
1128
1152
|
#
|
1129
1153
|
def delete_unspecified_locator
|
1130
1154
|
return nil if empty?
|
1131
|
-
loc
|
1155
|
+
loc = get_entry_e(self.size-1)
|
1132
1156
|
delete_locator(loc)
|
1133
1157
|
end
|
1134
1158
|
|
@@ -1594,13 +1618,12 @@ class Depq
|
|
1594
1618
|
end
|
1595
1619
|
|
1596
1620
|
def mm_find_top_loc
|
1597
|
-
|
1598
|
-
loc
|
1621
|
+
get_entry_e(0)
|
1599
1622
|
end
|
1600
1623
|
|
1601
1624
|
def mm_delete_loc(loc, upper)
|
1602
1625
|
i = loc.send(:index)
|
1603
|
-
|
1626
|
+
priority, subpriority = get_entry_ps(i)
|
1604
1627
|
last = self.size - 1
|
1605
1628
|
loc.send(:internal_deleted, priority, subpriority)
|
1606
1629
|
el, pl, sl = delete_last_entry
|
@@ -1666,8 +1689,8 @@ class Depq
|
|
1666
1689
|
end
|
1667
1690
|
|
1668
1691
|
def min_upper?(i, j)
|
1669
|
-
|
1670
|
-
|
1692
|
+
pi, si = get_entry_ps(i)
|
1693
|
+
pj, sj = get_entry_ps(j)
|
1671
1694
|
min_compare(pi, si, pj, sj) <= 0
|
1672
1695
|
end
|
1673
1696
|
|
@@ -1710,8 +1733,8 @@ class Depq
|
|
1710
1733
|
end
|
1711
1734
|
|
1712
1735
|
def max_upper?(i, j)
|
1713
|
-
|
1714
|
-
|
1736
|
+
pi, si = get_entry_ps(i)
|
1737
|
+
pj, sj = get_entry_ps(j)
|
1715
1738
|
max_compare(pi, si, pj, sj) >= 0
|
1716
1739
|
end
|
1717
1740
|
|
@@ -1761,14 +1784,14 @@ class Depq
|
|
1761
1784
|
def itv_child2_maxside(i) i &= ~1; i*2+5 end
|
1762
1785
|
|
1763
1786
|
def pcmp(i, j)
|
1764
|
-
|
1765
|
-
|
1787
|
+
pi = get_entry_p(i)
|
1788
|
+
pj = get_entry_p(j)
|
1766
1789
|
compare_priority(pi, pj)
|
1767
1790
|
end
|
1768
1791
|
|
1769
1792
|
def scmp(i, j)
|
1770
|
-
|
1771
|
-
|
1793
|
+
si = get_entry_s(i)
|
1794
|
+
sj = get_entry_s(j)
|
1772
1795
|
si <=> sj
|
1773
1796
|
end
|
1774
1797
|
|
@@ -1841,7 +1864,7 @@ class Depq
|
|
1841
1864
|
k = k1
|
1842
1865
|
elsif pc > 0
|
1843
1866
|
k = k2
|
1844
|
-
elsif
|
1867
|
+
elsif scmp(k1, k2) <= 0
|
1845
1868
|
k = k1
|
1846
1869
|
else
|
1847
1870
|
k = k2
|
@@ -1872,7 +1895,7 @@ class Depq
|
|
1872
1895
|
k = k2
|
1873
1896
|
elsif pc > 0
|
1874
1897
|
k = k1
|
1875
|
-
elsif
|
1898
|
+
elsif scmp(k1, k2) <= 0
|
1876
1899
|
k = k1
|
1877
1900
|
else
|
1878
1901
|
k = k2
|
@@ -1986,7 +2009,7 @@ class Depq
|
|
1986
2009
|
|
1987
2010
|
def itv_update_prio(loc, prio, subprio)
|
1988
2011
|
i = loc.send(:index)
|
1989
|
-
ei
|
2012
|
+
ei = get_entry_e(i)
|
1990
2013
|
set_entry(i, ei, prio, subprio)
|
1991
2014
|
range = 0...self.size
|
1992
2015
|
itv_adjust(i, range)
|
@@ -2012,15 +2035,15 @@ class Depq
|
|
2012
2035
|
when 0
|
2013
2036
|
[nil, nil]
|
2014
2037
|
when 1
|
2015
|
-
e0
|
2038
|
+
e0 = get_entry_e(0)
|
2016
2039
|
[e0, e0]
|
2017
2040
|
else
|
2018
2041
|
if pcmp(0, 1) == 0
|
2019
|
-
e0
|
2042
|
+
e0 = get_entry_e(0)
|
2020
2043
|
[e0, e0]
|
2021
2044
|
else
|
2022
|
-
e0
|
2023
|
-
e1
|
2045
|
+
e0 = get_entry_e(0)
|
2046
|
+
e1 = get_entry_e(1)
|
2024
2047
|
[e0, e1]
|
2025
2048
|
end
|
2026
2049
|
end
|
@@ -2036,7 +2059,7 @@ class Depq
|
|
2036
2059
|
|
2037
2060
|
def itv_delete_loc(loc)
|
2038
2061
|
i = loc.send(:index)
|
2039
|
-
|
2062
|
+
priority, subpriority = get_entry_ps(i)
|
2040
2063
|
last = self.size - 1
|
2041
2064
|
loc.send(:internal_deleted, priority, subpriority)
|
2042
2065
|
el, pl, sl = delete_last_entry
|
data/sample/dhondt.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# D'Hondt method
|
2
|
+
#
|
3
|
+
# usage:
|
4
|
+
# ruby -Ilib sample/dhondt.rb number-of-seats party1:votes1 party2:votes2 ...
|
5
|
+
#
|
6
|
+
# example:
|
7
|
+
# % ruby -Ilib sample/dhondt.rb 10 A:230000 B:120000 C:90000 D:30000
|
8
|
+
# A 230000 5
|
9
|
+
# B 120000 3
|
10
|
+
# C 90000 2
|
11
|
+
# D 30000 0
|
12
|
+
|
13
|
+
require 'depq'
|
14
|
+
|
15
|
+
def dhondt(number_of_seats, number_of_votes_for_parties)
|
16
|
+
q = Depq.new
|
17
|
+
number_of_votes_for_parties.each {|party, votes|
|
18
|
+
seats_gotten = 0
|
19
|
+
q.insert [party, votes, seats_gotten], Rational(votes, seats_gotten+1)
|
20
|
+
}
|
21
|
+
number_of_seats.times {
|
22
|
+
(party, votes, seats_gotten), priority = q.delete_max_priority
|
23
|
+
if !q.empty? && q.find_min_priority[1] == priority
|
24
|
+
# There may be two or more parties with maximum priority.
|
25
|
+
# Random choice should be implemented here...
|
26
|
+
raise
|
27
|
+
end
|
28
|
+
seats_gotten += 1
|
29
|
+
q.insert [party, votes, seats_gotten], Rational(votes, seats_gotten+1)
|
30
|
+
}
|
31
|
+
h = {}
|
32
|
+
until q.empty?
|
33
|
+
party, votes, seats_gotten = q.delete_max
|
34
|
+
h[party] = seats_gotten
|
35
|
+
end
|
36
|
+
h
|
37
|
+
end
|
38
|
+
|
39
|
+
number_of_seats = ARGV.shift.to_i
|
40
|
+
number_of_votes_for_parties = []
|
41
|
+
ARGV.each {|arg|
|
42
|
+
/\A(.*):(\d+)\z/ =~ arg
|
43
|
+
party = $1
|
44
|
+
votes = $2.to_i
|
45
|
+
number_of_votes_for_parties << [party, votes]
|
46
|
+
}
|
47
|
+
|
48
|
+
result = dhondt(number_of_seats, number_of_votes_for_parties)
|
49
|
+
|
50
|
+
number_of_votes_for_parties.each {|party, votes|
|
51
|
+
seats_gotten = result[party]
|
52
|
+
puts "#{party}\t#{votes}\t#{seats_gotten}"
|
53
|
+
}
|
data/test/test-depq.rb
CHANGED
@@ -3,26 +3,30 @@
|
|
3
3
|
# Copyright (C) 2009 Tanaka Akira <akr@fsij.org>
|
4
4
|
#
|
5
5
|
# Redistribution and use in source and binary forms, with or without
|
6
|
-
# modification, are permitted provided that the following conditions
|
6
|
+
# modification, are permitted provided that the following conditions
|
7
|
+
# are met:
|
7
8
|
#
|
8
|
-
# 1. Redistributions of source code must retain the above copyright
|
9
|
-
# list of conditions and the following disclaimer.
|
10
|
-
# 2. Redistributions in binary form must reproduce the above
|
11
|
-
# this list of conditions and the following
|
12
|
-
# and/or other materials provided
|
13
|
-
#
|
14
|
-
#
|
9
|
+
# 1. Redistributions of source code must retain the above copyright
|
10
|
+
# notice, this list of conditions and the following disclaimer.
|
11
|
+
# 2. Redistributions in binary form must reproduce the above
|
12
|
+
# copyright notice, this list of conditions and the following
|
13
|
+
# disclaimer in the documentation and/or other materials provided
|
14
|
+
# with the distribution.
|
15
|
+
# 3. The name of the author may not be used to endorse or promote
|
16
|
+
# products derived from this software without specific prior
|
17
|
+
# written permission.
|
15
18
|
#
|
16
|
-
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
17
|
-
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
-
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
-
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# IN
|
25
|
-
# OF
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
20
|
+
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
23
|
+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
25
|
+
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
27
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
28
|
+
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
29
|
+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
30
|
|
27
31
|
require 'depq'
|
28
32
|
require 'test/unit'
|
@@ -45,12 +49,12 @@ class Depq
|
|
45
49
|
end
|
46
50
|
|
47
51
|
def min_validation
|
48
|
-
mm_validation
|
52
|
+
mm_validation(&method(:min_upper?))
|
49
53
|
end
|
50
54
|
MinMode[:validation] = :min_validation
|
51
55
|
|
52
56
|
def max_validation
|
53
|
-
mm_validation
|
57
|
+
mm_validation(&method(:max_upper?))
|
54
58
|
end
|
55
59
|
MaxMode[:validation] = :max_validation
|
56
60
|
|
@@ -258,7 +262,7 @@ class TestDepq < Test::Unit::TestCase
|
|
258
262
|
q = Depq.new
|
259
263
|
a = q.insert("a", 2)
|
260
264
|
b = q.insert("b", 1)
|
261
|
-
|
265
|
+
q.insert("c", 3)
|
262
266
|
assert_equal(b, q.find_min_locator)
|
263
267
|
a.update("d", 0)
|
264
268
|
assert_equal("d", a.value)
|
@@ -275,11 +279,11 @@ class TestDepq < Test::Unit::TestCase
|
|
275
279
|
def test_locator_update_subpriority_min
|
276
280
|
q = Depq.new
|
277
281
|
a = q.insert("a", 1, 0)
|
278
|
-
|
282
|
+
q.insert("b", 2, 1)
|
279
283
|
c = q.insert("c", 1, 2)
|
280
|
-
|
281
|
-
|
282
|
-
|
284
|
+
q.insert("d", 2, 3)
|
285
|
+
q.insert("e", 1, 4)
|
286
|
+
q.insert("f", 2, 5)
|
283
287
|
assert_equal(a, q.find_min_locator)
|
284
288
|
a.update("A", 1, 10)
|
285
289
|
assert_equal(c, q.find_min_locator)
|
@@ -295,12 +299,12 @@ class TestDepq < Test::Unit::TestCase
|
|
295
299
|
|
296
300
|
def test_locator_update_subpriority_max
|
297
301
|
q = Depq.new
|
298
|
-
|
302
|
+
q.insert("a", 1, 0)
|
299
303
|
b = q.insert("b", 2, 1)
|
300
|
-
|
304
|
+
q.insert("c", 1, 2)
|
301
305
|
d = q.insert("d", 2, 3)
|
302
|
-
|
303
|
-
|
306
|
+
q.insert("e", 1, 4)
|
307
|
+
q.insert("f", 2, 5)
|
304
308
|
assert_equal(b, q.find_max_locator)
|
305
309
|
b.update("B", 2, 6)
|
306
310
|
assert_equal(d, q.find_max_locator)
|
@@ -316,7 +320,7 @@ class TestDepq < Test::Unit::TestCase
|
|
316
320
|
|
317
321
|
def test_locator_update_max
|
318
322
|
q = Depq.new
|
319
|
-
|
323
|
+
q.insert("a", 2)
|
320
324
|
b = q.insert("b", 1)
|
321
325
|
c = q.insert("c", 3)
|
322
326
|
assert_equal(c, q.find_max_locator)
|
@@ -624,7 +628,7 @@ class TestDepq < Test::Unit::TestCase
|
|
624
628
|
q = Depq.new
|
625
629
|
loc1 = q.insert 10
|
626
630
|
assert_equal([loc1, loc1], q.find_minmax_locator)
|
627
|
-
|
631
|
+
q.insert 10
|
628
632
|
assert_equal([loc1, loc1], q.find_minmax_locator)
|
629
633
|
end
|
630
634
|
|
metadata
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: depq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.7'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tanaka Akira
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
16
|
-
It is a data structure which can insert elements and delete elements with minimum
|
17
|
-
and maximum priority.
|
18
|
-
|
13
|
+
description: |
|
14
|
+
depq is a Double-Ended Priority Queue library.
|
15
|
+
It is a data structure which can insert elements and delete elements with minimum and maximum priority.
|
19
16
|
If there are elements which has same priority, the element inserted first is chosen.
|
20
|
-
|
21
17
|
The priority can be changed after the element is inserted.
|
22
|
-
|
23
|
-
'
|
24
18
|
email: akr@fsij.org
|
25
19
|
executables: []
|
26
20
|
extensions: []
|
@@ -28,6 +22,7 @@ extra_rdoc_files: []
|
|
28
22
|
files:
|
29
23
|
- README
|
30
24
|
- lib/depq.rb
|
25
|
+
- sample/dhondt.rb
|
31
26
|
- sample/dijkstra.rb
|
32
27
|
- sample/exqsort.rb
|
33
28
|
- sample/huffman.rb
|
@@ -37,29 +32,29 @@ files:
|
|
37
32
|
- sample/prim.rb
|
38
33
|
- sample/sched.rb
|
39
34
|
- test/test-depq.rb
|
40
|
-
homepage:
|
41
|
-
licenses:
|
35
|
+
homepage: https://github.com/akr/depq
|
36
|
+
licenses:
|
37
|
+
- BSD-3-Clause
|
38
|
+
metadata: {}
|
42
39
|
post_install_message:
|
43
40
|
rdoc_options: []
|
44
41
|
require_paths:
|
45
42
|
- lib
|
46
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
44
|
requirements:
|
49
|
-
- -
|
45
|
+
- - ">="
|
50
46
|
- !ruby/object:Gem::Version
|
51
47
|
version: '0'
|
52
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
49
|
requirements:
|
55
|
-
- -
|
50
|
+
- - ">="
|
56
51
|
- !ruby/object:Gem::Version
|
57
52
|
version: '0'
|
58
53
|
requirements: []
|
59
54
|
rubyforge_project: depq
|
60
|
-
rubygems_version:
|
55
|
+
rubygems_version: 2.2.2
|
61
56
|
signing_key:
|
62
|
-
specification_version:
|
57
|
+
specification_version: 4
|
63
58
|
summary: Stable Double-Ended Priority Queue.
|
64
59
|
test_files:
|
65
60
|
- test/test-depq.rb
|