Class: LemonGraph::NodeMap
- Inherits:
-
Object
- Object
- LemonGraph::NodeMap
- Includes:
- Enumerable
- Defined in:
- ext/lemongraph/lemongraph.cc
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if other is a NodeMap 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 node key.
-
#[]=(key, value) ⇒ Object
Associates the given value with the given node key; returns value.
-
#clear ⇒ self
Removes all values.
-
#default ⇒ Object
Returns the default value set for this node map.
-
#default=(dflt) ⇒ Object
Sets the default value for this node map.
-
#default_proc ⇒ Proc?
Returns the default proc set for this node map.
-
#default_proc=(proc) ⇒ Object
Sets the default proc for this node map.
-
#delete(key) ⇒ Object
Deletes the entry for the given node 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 node key and value pair.
-
#each_node ⇒ self, Enumerator
Calls the block, if given, once for each node key for which a value has been set.
-
#each_pair ⇒ self, Enumerator
Calls the block, if given, once for each node key and value pair.
-
#each_value ⇒ self, Enumerator
Calls the block, if given, once for each value that has been set.
-
#empty? ⇒ Boolean
Returns true if there are no entries, false otherwise.
-
#graph ⇒ Graph, Digraph
Returns the graph this node map is related to.
-
#has_node?(node) ⇒ Boolean
(also: #node?)
Returns true if a value was set for node, 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) ⇒ NodeMap
constructor
Returns a new node 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.
-
#nodes ⇒ Array<Graph::Node,Digraph::Node>
Returns an array containing all node keys for which a value has been set.
-
#values ⇒ Array<Object>
Returns an array containing all values set for nodes.
Constructor Details
#initialize(graph, default_value = nil) ⇒ NodeMap #initialize(graph) {|node, nodemap| ... } ⇒ NodeMap
Returns a new node map related to graph.
If no block is given, default_value will be returned when a value is fetched for a node for which no value was set.
If a block is given, it will be called if needed to provide values for nodes for which no value was set, instead of returning default_value.
702 703 704 705 706 707 708 709 710 711 |
# File 'ext/lemongraph/node_map.cc', line 702
VALUE lemongraph_nodemap_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::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
nm.initialize(self, rbg, dflt, proc);
return self;
}
|
Instance Method Details
#==(other) ⇒ Boolean
Returns true if other is a NodeMap and share the same graph, default value and proc as self and and all entries from other and self are equal (==).
992 993 994 995 996 997 998 999 |
# File 'ext/lemongraph/node_map.cc', line 992
VALUE lemongraph_nodemap_is_equal(VALUE self, VALUE other)
{
if (rb_obj_is_kind_of(other, c_NodeMap) != Qtrue)
return Qfalse;
LemonGraph::NodeMap& m = lemongraph_nodemap_rb2ref(self);
LemonGraph::NodeMap& o = lemongraph_nodemap_rb2ref(other);
return o.is_equal(m) ? Qtrue : Qfalse;
}
|
#[](key) ⇒ Object
Returns the value associated with the given node key.
804 805 806 807 808 |
# File 'ext/lemongraph/node_map.cc', line 804
VALUE lemongraph_nodemap_get(VALUE self, VALUE key)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.get(key);
}
|
#[]=(key, value) ⇒ Object
Associates the given value with the given node key; returns value.
815 816 817 818 819 820 |
# File 'ext/lemongraph/node_map.cc', line 815
VALUE lemongraph_nodemap_set(VALUE self, VALUE key, VALUE value)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
nm.set(key, value);
return value;
}
|
#clear ⇒ self
Removes all values.
927 928 929 930 931 932 |
# File 'ext/lemongraph/node_map.cc', line 927
VALUE lemongraph_nodemap_clear(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
nm.clear();
return self;
}
|
#default ⇒ Object
Returns the default value set for this node map.
755 756 757 758 759 |
# File 'ext/lemongraph/node_map.cc', line 755
VALUE lemongraph_nodemap_get_dflt_val(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.default_value();
}
|
#default=(dflt) ⇒ Object
Sets the default value for this node map.
764 765 766 767 768 769 |
# File 'ext/lemongraph/node_map.cc', line 764
VALUE lemongraph_nodemap_set_dflt_val(VALUE self, VALUE dflt)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
nm.set_default_value(dflt);
return self;
}
|
#default_proc ⇒ Proc?
Returns the default proc set for this node map.
775 776 777 778 779 |
# File 'ext/lemongraph/node_map.cc', line 775
VALUE lemongraph_nodemap_get_dflt_proc(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.default_proc();
}
|
#default_proc=(proc) ⇒ Object
Sets the default proc for this node map.
If set, the default proc is called when a value is fetched for a node which was not assigned a value. The proc parameters must be the node key and the node map.
Set to nil to reset it so that the default value is returned when needed instead of calling the default proc.
792 793 794 795 796 797 |
# File 'ext/lemongraph/node_map.cc', line 792
VALUE lemongraph_nodemap_set_dflt_proc(VALUE self, VALUE proc)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
nm.set_default_proc(proc);
return self;
}
|
#delete(key) ⇒ Object
Deletes the entry for the given node and returns its associated value, or the default one.
938 939 940 941 942 |
# File 'ext/lemongraph/node_map.cc', line 938
VALUE lemongraph_nodemap_delete(VALUE self, VALUE key)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.del(key);
}
|
#delete_if {|node, 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.
960 961 962 963 964 |
# File 'ext/lemongraph/node_map.cc', line 960
VALUE lemongraph_nodemap_delete_if(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.del_if();
}
|
#each_pair {|node, value| ... } ⇒ self #each_pair ⇒ Enumerator #each {|node, value| ... } ⇒ self #each ⇒ Enumerator
Calls the block, if given, once for each node key and value pair. The nodes and values are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
917 918 919 920 921 |
# File 'ext/lemongraph/node_map.cc', line 917
VALUE lemongraph_nodemap_each_pair(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.each_pair();
}
|
#each_node {|node| ... } ⇒ self #each_node ⇒ Enumerator
Calls the block, if given, once for each node key for which a value has been set. The nodes are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
874 875 876 877 878 |
# File 'ext/lemongraph/node_map.cc', line 874
VALUE lemongraph_nodemap_each_node(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.each_node();
}
|
#each_pair {|node, value| ... } ⇒ self #each_pair ⇒ Enumerator #each {|node, value| ... } ⇒ self #each ⇒ Enumerator
Calls the block, if given, once for each node key and value pair. The nodes and values are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
917 918 919 920 921 |
# File 'ext/lemongraph/node_map.cc', line 917
VALUE lemongraph_nodemap_each_pair(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_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.
892 893 894 895 896 |
# File 'ext/lemongraph/node_map.cc', line 892
VALUE lemongraph_nodemap_each_value(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.each_value();
}
|
#empty? ⇒ Boolean
Returns true if there are no entries, false otherwise
856 857 858 859 860 |
# File 'ext/lemongraph/node_map.cc', line 856
VALUE lemongraph_nodemap_is_empty(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.is_empty();
}
|
#graph ⇒ Graph, Digraph
Returns the graph this node map is related to.
745 746 747 748 749 |
# File 'ext/lemongraph/node_map.cc', line 745
VALUE lemongraph_nodemap_graph(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.graph();
}
|
#has_node?(node) ⇒ Boolean Also known as: node?
Returns true if a value was set for node, otherwise false.
971 972 973 974 975 |
# File 'ext/lemongraph/node_map.cc', line 971
VALUE lemongraph_nodemap_has_node(VALUE self, VALUE node)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.has_node(node);
}
|
#has_value?(value) ⇒ Boolean Also known as: value?
Returns true if value is a value in self, otherwise false.
981 982 983 984 985 |
# File 'ext/lemongraph/node_map.cc', line 981
VALUE lemongraph_nodemap_has_value(VALUE self, VALUE value)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.has_value(value);
}
|
#hash ⇒ Integer
Returns the integer hash value for self.
1005 1006 1007 1008 1009 |
# File 'ext/lemongraph/node_map.cc', line 1005
VALUE lemongraph_nodemap_hash(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.hash();
}
|
#initialize_copy(orig) ⇒ self
Method called by dup and clone methods.
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'ext/lemongraph/node_map.cc', line 718
VALUE lemongraph_nodemap_initialize_copy(VALUE self, VALUE orig)
{
rb_call_super(1, &orig);
LemonGraph::NodeMap& from = lemongraph_nodemap_rb2ref(orig);
LemonGraph::NodeMap& to = lemongraph_nodemap_rb2ref(self);
to.initialize(self, from.graph(), from.default_value(), from.default_proc());
if (from.is_for_directed_graph()) {
for (lemon::ListDigraph::NodeIt n(lemongraph_digraph_rb2ref(from.graph())); n != lemon::INVALID; ++n) {
const LemonGraph::RBValue& v = from[n];
if (v.is_valid())
to[n] = v;
}
}
else {
for (lemon::ListGraph::NodeIt n(lemongraph_graph_rb2ref(from.graph())); n != lemon::INVALID; ++n) {
const LemonGraph::RBValue& v = from[n];
if (v.is_valid())
to[n] = v;
}
}
return self;
}
|
#length ⇒ Integer
Return the count of entries in slef for which a value has been set
846 847 848 849 850 |
# File 'ext/lemongraph/node_map.cc', line 846
VALUE lemongraph_nodemap_length(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.length();
}
|
#nodes ⇒ Array<Graph::Node,Digraph::Node>
Returns an array containing all node keys for which a value has been set.
826 827 828 829 830 |
# File 'ext/lemongraph/node_map.cc', line 826
VALUE lemongraph_nodemap_nodes(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.keys();
}
|
#values ⇒ Array<Object>
Returns an array containing all values set for nodes.
836 837 838 839 840 |
# File 'ext/lemongraph/node_map.cc', line 836
VALUE lemongraph_nodemap_values(VALUE self)
{
LemonGraph::NodeMap& nm = lemongraph_nodemap_rb2ref(self);
return nm.values();
}
|