Class: PenguinQueue::Node

Inherits:
Object
  • Object
show all
Defined in:
ext/penguin_queue/penguin_queue.c

Instance Method Summary collapse

Instance Method Details

#deleteObject



208
209
210
211
212
# File 'ext/penguin_queue/penguin_queue.c', line 208

VALUE node_remove(VALUE self){
  NODE_PREPARE(self, nptr);
  queue_remove_node(nptr->queue, self);
  return Qnil;
}

#inspectObject



44
45
46
47
48
49
50
51
52
53
54
# File 'ext/penguin_queue/penguin_queue.c', line 44

VALUE node_inspect(VALUE self){
  VALUE str = rb_str_buf_new(0);
  NODE_PREPARE(self, nptr);
  rb_str_buf_append(str, rb_class_name(CLASS_OF(self)));
  RB_STR_BUF_CAT(str, "{priority: ");
  rb_str_buf_append(str, rb_inspect(nptr->priority));
  RB_STR_BUF_CAT(str, ", value: ");
  rb_str_buf_append(str, rb_inspect(nptr->value));
  RB_STR_BUF_CAT(str, "}");
  return str;
}

#priorityObject



36
37
38
39
# File 'ext/penguin_queue/penguin_queue.c', line 36

VALUE node_pri(VALUE self){
  NODE_PREPARE(self, ptr);
  return ptr->priority;
}

#priority=(priority) ⇒ Object



237
238
239
240
241
242
243
244
245
# File 'ext/penguin_queue/penguin_queue.c', line 237

VALUE node_update_priority(VALUE node, VALUE priority){
  NODE_DECLARE_PTR(nptr);
  QUEUE_DECLARE_PTR(ptr);
  NODE_GET_PTR(node, nptr);
  QUEUE_GET_PTR(nptr->queue, ptr);
  if(ptr->compare_by != Qnil)rb_raise(rb_eRuntimeError, "priority update not supported on queue initialized with block");
  node_update_priority_internal(node, priority);
  return priority;
}

#removeObject



208
209
210
211
212
# File 'ext/penguin_queue/penguin_queue.c', line 208

VALUE node_remove(VALUE self){
  NODE_PREPARE(self, nptr);
  queue_remove_node(nptr->queue, self);
  return Qnil;
}

#to_sObject



44
45
46
47
48
49
50
51
52
53
54
# File 'ext/penguin_queue/penguin_queue.c', line 44

VALUE node_inspect(VALUE self){
  VALUE str = rb_str_buf_new(0);
  NODE_PREPARE(self, nptr);
  rb_str_buf_append(str, rb_class_name(CLASS_OF(self)));
  RB_STR_BUF_CAT(str, "{priority: ");
  rb_str_buf_append(str, rb_inspect(nptr->priority));
  RB_STR_BUF_CAT(str, ", value: ");
  rb_str_buf_append(str, rb_inspect(nptr->value));
  RB_STR_BUF_CAT(str, "}");
  return str;
}

#valueObject



40
41
42
43
# File 'ext/penguin_queue/penguin_queue.c', line 40

VALUE node_val(VALUE self){
  NODE_PREPARE(self, ptr);
  return ptr->value;
}

#value=(value) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
# File 'ext/penguin_queue/penguin_queue.c', line 247

VALUE node_update_value(VALUE node, VALUE value){
  NODE_DECLARE_PTR(nptr);
  QUEUE_DECLARE_PTR(ptr);
  NODE_GET_PTR(node, nptr);
  QUEUE_GET_PTR(nptr->queue, ptr);
  nptr->value = value;
  if(ptr->compare_by != Qnil){
    VALUE priority = rb_funcall(ptr->compare_by, id_call, 1, value);
    node_update_priority_internal(node, priority);
  }
  return value;
}