penguin_queue 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/ext/penguin_queue/penguin_queue.c +6 -9
- data/lib/penguin_queue/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d70fcdcdbb5aebbebec83821a6127e80fc6f583
|
4
|
+
data.tar.gz: 0efca553d509e7a8951f9c3cd44315dff21d632b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bceb560f69ff8e4f61afcc0a227ad7d43c10b960c0d4a1c487c3e874eb51a9950573521ef4c5159f55d6ab87ad38d8f7d0a9d80ea8e003cab4be93c4542b873a
|
7
|
+
data.tar.gz: 4fa133b95cf698d674ba7ae9eb5831500a213f2f78a0781237f6d9345dc5a67bc50b742818b91639488d4496656457292ce57842f0b8bcf43eaab4735e67b3b6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,7 +38,7 @@ pq.size.times.map { pq.deq } #=> [8, 6, 4, 2, 0]
|
|
38
38
|
```ruby
|
39
39
|
# initialize
|
40
40
|
PenguinQueue.new
|
41
|
-
PenguinQueue.new(order
|
41
|
+
PenguinQueue.new(order) # min(default) or max
|
42
42
|
PenguinQueue.new(&calc_priority_from_element_proc)
|
43
43
|
# enqueue
|
44
44
|
<<(e) enq(e) push(e) unshift(e)
|
@@ -89,10 +89,8 @@ VALUE queue_alloc(VALUE klass){
|
|
89
89
|
VALUE queue_initialize(int argc, VALUE *argv, VALUE self){
|
90
90
|
QUEUE_PREPARE(self, ptr);
|
91
91
|
VALUE opts, order;
|
92
|
-
if(
|
93
|
-
|
94
|
-
rb_get_kwargs(opts, keyword_ids, 0, 1, &order);
|
95
|
-
if(order == Qundef)return self;
|
92
|
+
if(argc == 0)return self;
|
93
|
+
rb_scan_args(argc, argv, "1", &order);
|
96
94
|
if(order == ID2SYM(id_max)){
|
97
95
|
ptr->compare_sgn = -1;
|
98
96
|
}else if(order != ID2SYM(id_min)){
|
@@ -120,7 +118,7 @@ void queue_up(VALUE self, VALUE node){
|
|
120
118
|
VALUE pnode = heap[pindex];
|
121
119
|
NODE_PREPARE(pnode, pptr);
|
122
120
|
long cmp = compare(pptr->priority, nptr->priority)*sgn;
|
123
|
-
if(!cmp)cmp=compare_id(pptr->id, nptr->id)
|
121
|
+
if(!cmp)cmp=compare_id(pptr->id, nptr->id);
|
124
122
|
if(cmp<0)break;
|
125
123
|
pptr->index = index;
|
126
124
|
heap[index] = pnode;
|
@@ -146,7 +144,7 @@ void queue_down(VALUE self, VALUE node){
|
|
146
144
|
VALUE rnode = heap[lindex+1];
|
147
145
|
NODE_PREPARE(rnode, rptr);
|
148
146
|
long cmp = compare(lptr->priority, rptr->priority)*sgn;
|
149
|
-
if(!cmp)cmp=compare_id(lptr->id, rptr->id)
|
147
|
+
if(!cmp)cmp=compare_id(lptr->id, rptr->id);
|
150
148
|
if(cmp >= 0){
|
151
149
|
lindex += 1;
|
152
150
|
lnode = rnode;
|
@@ -154,7 +152,7 @@ void queue_down(VALUE self, VALUE node){
|
|
154
152
|
}
|
155
153
|
}
|
156
154
|
long cmp = compare(nptr->priority, lptr->priority)*sgn;
|
157
|
-
if(!cmp)cmp=compare_id(nptr->id, lptr->id)
|
155
|
+
if(!cmp)cmp=compare_id(nptr->id, lptr->id);
|
158
156
|
if(cmp <= 0)break;
|
159
157
|
lptr->index = index;
|
160
158
|
heap[index] = lnode;
|
@@ -179,7 +177,7 @@ VALUE queue_remove_node(VALUE self, VALUE node){
|
|
179
177
|
heap[nptr->index] = replace_node;
|
180
178
|
rptr->index = nptr->index;
|
181
179
|
long cmp = compare(rptr->priority, nptr->priority)*sgn;
|
182
|
-
if(!cmp)cmp = compare_id(rptr->id, nptr->id)
|
180
|
+
if(!cmp)cmp = compare_id(rptr->id, nptr->id);
|
183
181
|
if(cmp > 0){
|
184
182
|
queue_down(nptr->queue, replace_node);
|
185
183
|
}else{
|
@@ -364,7 +362,6 @@ void Init_penguin_queue(void){
|
|
364
362
|
id_cmp = rb_intern("<=>");
|
365
363
|
id_max = rb_intern("max");
|
366
364
|
id_min = rb_intern("min");
|
367
|
-
id_order = rb_intern("order");
|
368
365
|
|
369
366
|
VALUE queue_class = rb_define_class("PenguinQueue", rb_cObject);
|
370
367
|
rb_define_alloc_func(queue_class, queue_alloc);
|