Class: LemonGraph::EdgeMap
- Inherits:
-
Object
- Object
- LemonGraph::EdgeMap
- Includes:
- Enumerable
- Defined in:
- ext/lemongraph/lemongraph.cc
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if other is a EdgeMap and share the same graph, default value and proc as self and and all entries from other and self are equal (==).
-
#[](key) ⇒ Object
Returns the value associated with the given edge key.
-
#[]=(key, value) ⇒ Object
Associates the given value with the given edge key; returns value.
-
#clear ⇒ self
Removes all values.
-
#default ⇒ Object
Returns the default value set for this edge map.
-
#default=(dflt) ⇒ Object
Sets the default value for this edge map.
-
#default_proc ⇒ Proc?
Returns the default proc set for this edge map.
-
#default_proc=(proc) ⇒ Object
Sets the default proc for this edge map.
-
#delete(key) ⇒ Object
Deletes the entry for the given edge and returns its associated value, or the default one.
-
#delete_if ⇒ self, Enumerator
Delete entries for which the block returns a truthy value.
-
#each ⇒ self, Enumerator
Calls the block, if given, once for each edge key and value pair.
-
#each_edge ⇒ self, Enumerator
Calls the block, if given, once for each edge key for which a value has been set.
-
#each_pair ⇒ self, Enumerator
Calls the block, if given, once for each edge key and value pair.
-
#each_value ⇒ self, Enumerator
Calls the block, if given, once for each value that has been set.
-
#edges ⇒ Array<Graph::Edge,Digraph::Edge>
Returns an array containing all edge keys for which a value has been set.
-
#empty? ⇒ Boolean
Returns true if there are no entries, false otherwise.
-
#graph ⇒ Graph, Digraph
Returns the graph this edge map is related to.
-
#has_edge?(edge) ⇒ Boolean
(also: #edge?)
Returns true if a value was set for edge, otherwise false.
-
#has_value?(value) ⇒ Boolean
(also: #value?)
Returns true if value is a value in self, otherwise false.
-
#hash ⇒ Integer
Returns the integer hash value for self.
-
#initialize(*args) ⇒ EdgeMap
constructor
Returns a new edge map related to graph.
-
#initialize_copy(orig) ⇒ self
Method called by dup and clone methods.
-
#length ⇒ Integer
Return the count of entries in slef for which a value has been set.
-
#values ⇒ Array<Object>
Returns an array containing all values set for edges.
Constructor Details
#initialize(graph, default_value = nil) ⇒ EdgeMap #initialize(graph) {|edge, edgemap| ... } ⇒ EdgeMap
Returns a new edge map related to graph.
If no block is given, default_value will be returned when a value is fetched for a edge for which no value was set.
If a block is given, it will be called if needed to provide values for edges for which no value was set, instead of returning default_value.
470 471 472 473 474 475 476 477 478 479 |
# File 'ext/lemongraph/edge_map.cc', line 470
VALUE lemongraph_edgemap_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE rbg;
VALUE dflt = Qnil;
VALUE proc = Qnil;
rb_scan_args(argc, argv, "11&", &rbg, &dflt, &proc);
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
nm.initialize(self, rbg, dflt, proc);
return self;
}
|
Instance Method Details
#==(other) ⇒ Boolean
Returns true if other is a EdgeMap and share the same graph, default value and proc as self and and all entries from other and self are equal (==).
751 752 753 754 755 756 757 758 |
# File 'ext/lemongraph/edge_map.cc', line 751
VALUE lemongraph_edgemap_is_equal(VALUE self, VALUE other)
{
if (rb_obj_is_kind_of(other, c_EdgeMap) != Qtrue)
return Qfalse;
LemonGraph::EdgeMap& m = lemongraph_edgemap_rb2ref(self);
LemonGraph::EdgeMap& o = lemongraph_edgemap_rb2ref(other);
return o.is_equal(m) ? Qtrue : Qfalse;
}
|
#[](key) ⇒ Object
Returns the value associated with the given edge key.
563 564 565 566 567 |
# File 'ext/lemongraph/edge_map.cc', line 563
VALUE lemongraph_edgemap_get(VALUE self, VALUE key)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.get(key);
}
|
#[]=(key, value) ⇒ Object
Associates the given value with the given edge key; returns value.
574 575 576 577 578 579 |
# File 'ext/lemongraph/edge_map.cc', line 574
VALUE lemongraph_edgemap_set(VALUE self, VALUE key, VALUE value)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
nm.set(key, value);
return value;
}
|
#clear ⇒ self
Removes all values.
686 687 688 689 690 691 |
# File 'ext/lemongraph/edge_map.cc', line 686
VALUE lemongraph_edgemap_clear(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
nm.clear();
return self;
}
|
#default ⇒ Object
Returns the default value set for this edge map.
514 515 516 517 518 |
# File 'ext/lemongraph/edge_map.cc', line 514
VALUE lemongraph_edgemap_get_dflt_val(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.default_value();
}
|
#default=(dflt) ⇒ Object
Sets the default value for this edge map.
523 524 525 526 527 528 |
# File 'ext/lemongraph/edge_map.cc', line 523
VALUE lemongraph_edgemap_set_dflt_val(VALUE self, VALUE dflt)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
nm.set_default_value(dflt);
return self;
}
|
#default_proc ⇒ Proc?
Returns the default proc set for this edge map.
534 535 536 537 538 |
# File 'ext/lemongraph/edge_map.cc', line 534
VALUE lemongraph_edgemap_get_dflt_proc(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.default_proc();
}
|
#default_proc=(proc) ⇒ Object
Sets the default proc for this edge map.
If set, the default proc is called when a value is fetched for a edge which was not assigned a value. The proc parameters must be the edge key and the edge map.
Set to nil to reset it so that the default value is returned when needed instead of calling the default proc.
551 552 553 554 555 556 |
# File 'ext/lemongraph/edge_map.cc', line 551
VALUE lemongraph_edgemap_set_dflt_proc(VALUE self, VALUE proc)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
nm.set_default_proc(proc);
return self;
}
|
#delete(key) ⇒ Object
Deletes the entry for the given edge and returns its associated value, or the default one.
697 698 699 700 701 |
# File 'ext/lemongraph/edge_map.cc', line 697
VALUE lemongraph_edgemap_delete(VALUE self, VALUE key)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.del(key);
}
|
#delete_if {|edge, value| ... } ⇒ self #delete_if ⇒ Enumerator
Delete entries for which the block returns a truthy value. Returns self, or, if no block is given, an Enumerator is returned.
719 720 721 722 723 |
# File 'ext/lemongraph/edge_map.cc', line 719
VALUE lemongraph_edgemap_delete_if(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.del_if();
}
|
#each_pair {|edge, value| ... } ⇒ self #each_pair ⇒ Enumerator #each {|edge, value| ... } ⇒ self #each ⇒ Enumerator
Calls the block, if given, once for each edge key and value pair. The edges and values are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
676 677 678 679 680 |
# File 'ext/lemongraph/edge_map.cc', line 676
VALUE lemongraph_edgemap_each_pair(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.each_pair();
}
|
#each_edge {|edge| ... } ⇒ self #each_edge ⇒ Enumerator
Calls the block, if given, once for each edge key for which a value has been set. The edges are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
633 634 635 636 637 |
# File 'ext/lemongraph/edge_map.cc', line 633
VALUE lemongraph_edgemap_each_edge(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.each_edge();
}
|
#each_pair {|edge, value| ... } ⇒ self #each_pair ⇒ Enumerator #each {|edge, value| ... } ⇒ self #each ⇒ Enumerator
Calls the block, if given, once for each edge key and value pair. The edges and values are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
676 677 678 679 680 |
# File 'ext/lemongraph/edge_map.cc', line 676
VALUE lemongraph_edgemap_each_pair(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.each_pair();
}
|
#each_value {|value| ... } ⇒ self #each_value ⇒ Enumerator
Calls the block, if given, once for each value that has been set. The values are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
651 652 653 654 655 |
# File 'ext/lemongraph/edge_map.cc', line 651
VALUE lemongraph_edgemap_each_value(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.each_value();
}
|
#edges ⇒ Array<Graph::Edge,Digraph::Edge>
Returns an array containing all edge keys for which a value has been set.
585 586 587 588 589 |
# File 'ext/lemongraph/edge_map.cc', line 585
VALUE lemongraph_edgemap_edges(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.keys();
}
|
#empty? ⇒ Boolean
Returns true if there are no entries, false otherwise
615 616 617 618 619 |
# File 'ext/lemongraph/edge_map.cc', line 615
VALUE lemongraph_edgemap_is_empty(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.is_empty();
}
|
#graph ⇒ Graph, Digraph
Returns the graph this edge map is related to.
504 505 506 507 508 |
# File 'ext/lemongraph/edge_map.cc', line 504
VALUE lemongraph_edgemap_graph(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.graph();
}
|
#has_edge?(edge) ⇒ Boolean Also known as: edge?
Returns true if a value was set for edge, otherwise false.
730 731 732 733 734 |
# File 'ext/lemongraph/edge_map.cc', line 730
VALUE lemongraph_edgemap_has_edge(VALUE self, VALUE edge)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.has_edge(edge);
}
|
#has_value?(value) ⇒ Boolean Also known as: value?
Returns true if value is a value in self, otherwise false.
740 741 742 743 744 |
# File 'ext/lemongraph/edge_map.cc', line 740
VALUE lemongraph_edgemap_has_value(VALUE self, VALUE value)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.has_value(value);
}
|
#hash ⇒ Integer
Returns the integer hash value for self.
764 765 766 767 768 |
# File 'ext/lemongraph/edge_map.cc', line 764
VALUE lemongraph_edgemap_hash(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.hash();
}
|
#initialize_copy(orig) ⇒ self
Method called by dup and clone methods.
486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'ext/lemongraph/edge_map.cc', line 486
VALUE lemongraph_edgemap_initialize_copy(VALUE self, VALUE orig)
{
rb_call_super(1, &orig);
LemonGraph::EdgeMap& from = lemongraph_edgemap_rb2ref(orig);
LemonGraph::EdgeMap& to = lemongraph_edgemap_rb2ref(self);
to.initialize(self, from.graph(), from.default_value(), from.default_proc());
for (lemon::ListGraph::EdgeIt e(lemongraph_graph_rb2ref(from.graph())); e != lemon::INVALID; ++e) {
const LemonGraph::RBValue& v = from[e];
if (v.is_valid())
to[e] = v;
}
return self;
}
|
#length ⇒ Integer
Return the count of entries in slef for which a value has been set
605 606 607 608 609 |
# File 'ext/lemongraph/edge_map.cc', line 605
VALUE lemongraph_edgemap_length(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.length();
}
|
#values ⇒ Array<Object>
Returns an array containing all values set for edges.
595 596 597 598 599 |
# File 'ext/lemongraph/edge_map.cc', line 595
VALUE lemongraph_edgemap_values(VALUE self)
{
LemonGraph::EdgeMap& nm = lemongraph_edgemap_rb2ref(self);
return nm.values();
}
|