penguin_queue 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4fd3cc82db722d18ca04d5041814b763bb57b2c
4
- data.tar.gz: ef46be32133f2656159e46f7adf8ddf7960386ee
3
+ metadata.gz: 9d70fcdcdbb5aebbebec83821a6127e80fc6f583
4
+ data.tar.gz: 0efca553d509e7a8951f9c3cd44315dff21d632b
5
5
  SHA512:
6
- metadata.gz: f23b0a538c39f318e66a28e37d5182d619182070ad71db09599f6d0dc286b1426c6d10a631708e93803dd5ee517ba65c3d163d4734496e5c86c85754965df064
7
- data.tar.gz: 7e75329a8025a5d5090b40d053b23d884831d35d68b29f297a88e2fd6fa2d08c67474670a3aabe6dbefdd79c03124adf2eb7cefb90106775621e7527c57cb8d0
6
+ metadata.gz: bceb560f69ff8e4f61afcc0a227ad7d43c10b960c0d4a1c487c3e874eb51a9950573521ef4c5159f55d6ab87ad38d8f7d0a9d80ea8e003cab4be93c4542b873a
7
+ data.tar.gz: 4fa133b95cf698d674ba7ae9eb5831500a213f2f78a0781237f6d9345dc5a67bc50b742818b91639488d4496656457292ce57842f0b8bcf43eaab4735e67b3b6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- penguin_queue (0.1.1)
4
+ penguin_queue (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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: :max) # min(default) or max
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(!OPTHASH_GIVEN_P(opts))return self;
93
- ID keyword_ids[] = {id_order};
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)*sgn;
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)*sgn;
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)*sgn;
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)*sgn;
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);
@@ -1,3 +1,3 @@
1
1
  class PenguinQueue
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: penguin_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng