Class: LemonGraph::ArcMap
- Inherits:
-
Object
- Object
- LemonGraph::ArcMap
- Includes:
- Enumerable
- Defined in:
- ext/lemongraph/lemongraph.cc
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if other is a ArcMap 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 arc key.
-
#[]=(key, value) ⇒ Object
Associates the given value with the given arc key; returns value.
-
#arcs ⇒ Array<Graph::Arc,Digraph::Arc>
Returns an array containing all arc keys for which a value has been set.
-
#clear ⇒ self
Removes all values.
-
#default ⇒ Object
Returns the default value set for this arc map.
-
#default=(dflt) ⇒ Object
Sets the default value for this arc map.
-
#default_proc ⇒ Proc?
Returns the default proc set for this arc map.
-
#default_proc=(proc) ⇒ Object
Sets the default proc for this arc map.
-
#delete(key) ⇒ Object
Deletes the entry for the given arc 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 arc key and value pair.
-
#each_arc ⇒ self, Enumerator
Calls the block, if given, once for each arc key for which a value has been set.
-
#each_pair ⇒ self, Enumerator
Calls the block, if given, once for each arc 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 arc map is related to.
-
#has_arc?(arc) ⇒ Boolean
(also: #arc?)
Returns true if a value was set for arc, 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) ⇒ ArcMap
constructor
Returns a new arc 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 arcs.
Constructor Details
#initialize(graph, default_value = nil) ⇒ ArcMap #initialize(graph) {|arc, arcmap| ... } ⇒ ArcMap
Returns a new arc map related to graph.
If no block is given, default_value will be returned when a value is fetched for a arc for which no value was set.
If a block is given, it will be called if needed to provide values for arcs for which no value was set, instead of returning default_value.
697 698 699 700 701 702 703 704 705 706 |
# File 'ext/lemongraph/arc_map.cc', line 697
VALUE lemongraph_arcmap_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::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
nm.initialize(self, rbg, dflt, proc);
return self;
}
|
Instance Method Details
#==(other) ⇒ Boolean
Returns true if other is a ArcMap and share the same graph, default value and proc as self and and all entries from other and self are equal (==).
987 988 989 990 991 992 993 994 |
# File 'ext/lemongraph/arc_map.cc', line 987
VALUE lemongraph_arcmap_is_equal(VALUE self, VALUE other)
{
if (rb_obj_is_kind_of(other, c_ArcMap) != Qtrue)
return Qfalse;
LemonGraph::ArcMap& m = lemongraph_arcmap_rb2ref(self);
LemonGraph::ArcMap& o = lemongraph_arcmap_rb2ref(other);
return o.is_equal(m) ? Qtrue : Qfalse;
}
|
#[](key) ⇒ Object
Returns the value associated with the given arc key.
799 800 801 802 803 |
# File 'ext/lemongraph/arc_map.cc', line 799
VALUE lemongraph_arcmap_get(VALUE self, VALUE key)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.get(key);
}
|
#[]=(key, value) ⇒ Object
Associates the given value with the given arc key; returns value.
810 811 812 813 814 815 |
# File 'ext/lemongraph/arc_map.cc', line 810
VALUE lemongraph_arcmap_set(VALUE self, VALUE key, VALUE value)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
nm.set(key, value);
return value;
}
|
#arcs ⇒ Array<Graph::Arc,Digraph::Arc>
Returns an array containing all arc keys for which a value has been set.
821 822 823 824 825 |
# File 'ext/lemongraph/arc_map.cc', line 821
VALUE lemongraph_arcmap_arcs(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.keys();
}
|
#clear ⇒ self
Removes all values.
922 923 924 925 926 927 |
# File 'ext/lemongraph/arc_map.cc', line 922
VALUE lemongraph_arcmap_clear(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
nm.clear();
return self;
}
|
#default ⇒ Object
Returns the default value set for this arc map.
750 751 752 753 754 |
# File 'ext/lemongraph/arc_map.cc', line 750
VALUE lemongraph_arcmap_get_dflt_val(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.default_value();
}
|
#default=(dflt) ⇒ Object
Sets the default value for this arc map.
759 760 761 762 763 764 |
# File 'ext/lemongraph/arc_map.cc', line 759
VALUE lemongraph_arcmap_set_dflt_val(VALUE self, VALUE dflt)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
nm.set_default_value(dflt);
return self;
}
|
#default_proc ⇒ Proc?
Returns the default proc set for this arc map.
770 771 772 773 774 |
# File 'ext/lemongraph/arc_map.cc', line 770
VALUE lemongraph_arcmap_get_dflt_proc(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.default_proc();
}
|
#default_proc=(proc) ⇒ Object
Sets the default proc for this arc map.
If set, the default proc is called when a value is fetched for a arc which was not assigned a value. The proc parameters must be the arc key and the arc map.
Set to nil to reset it so that the default value is returned when needed instead of calling the default proc.
787 788 789 790 791 792 |
# File 'ext/lemongraph/arc_map.cc', line 787
VALUE lemongraph_arcmap_set_dflt_proc(VALUE self, VALUE proc)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
nm.set_default_proc(proc);
return self;
}
|
#delete(key) ⇒ Object
Deletes the entry for the given arc and returns its associated value, or the default one.
933 934 935 936 937 |
# File 'ext/lemongraph/arc_map.cc', line 933
VALUE lemongraph_arcmap_delete(VALUE self, VALUE key)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.del(key);
}
|
#delete_if {|arc, 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.
955 956 957 958 959 |
# File 'ext/lemongraph/arc_map.cc', line 955
VALUE lemongraph_arcmap_delete_if(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.del_if();
}
|
#each_pair {|arc, value| ... } ⇒ self #each_pair ⇒ Enumerator #each {|arc, value| ... } ⇒ self #each ⇒ Enumerator
Calls the block, if given, once for each arc key and value pair. The arcs and values are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
912 913 914 915 916 |
# File 'ext/lemongraph/arc_map.cc', line 912
VALUE lemongraph_arcmap_each_pair(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.each_pair();
}
|
#each_arc {|arc| ... } ⇒ self #each_arc ⇒ Enumerator
Calls the block, if given, once for each arc key for which a value has been set. The arcs are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
869 870 871 872 873 |
# File 'ext/lemongraph/arc_map.cc', line 869
VALUE lemongraph_arcmap_each_arc(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.each_arc();
}
|
#each_pair {|arc, value| ... } ⇒ self #each_pair ⇒ Enumerator #each {|arc, value| ... } ⇒ self #each ⇒ Enumerator
Calls the block, if given, once for each arc key and value pair. The arcs and values are passed as parameters to the block.
Returns self, or, if no block is given, an Enumerator is returned.
912 913 914 915 916 |
# File 'ext/lemongraph/arc_map.cc', line 912
VALUE lemongraph_arcmap_each_pair(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_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.
887 888 889 890 891 |
# File 'ext/lemongraph/arc_map.cc', line 887
VALUE lemongraph_arcmap_each_value(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.each_value();
}
|
#empty? ⇒ Boolean
Returns true if there are no entries, false otherwise
851 852 853 854 855 |
# File 'ext/lemongraph/arc_map.cc', line 851
VALUE lemongraph_arcmap_is_empty(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.is_empty();
}
|
#graph ⇒ Graph, Digraph
Returns the graph this arc map is related to.
740 741 742 743 744 |
# File 'ext/lemongraph/arc_map.cc', line 740
VALUE lemongraph_arcmap_graph(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.graph();
}
|
#has_arc?(arc) ⇒ Boolean Also known as: arc?
Returns true if a value was set for arc, otherwise false.
966 967 968 969 970 |
# File 'ext/lemongraph/arc_map.cc', line 966
VALUE lemongraph_arcmap_has_arc(VALUE self, VALUE arc)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.has_arc(arc);
}
|
#has_value?(value) ⇒ Boolean Also known as: value?
Returns true if value is a value in self, otherwise false.
976 977 978 979 980 |
# File 'ext/lemongraph/arc_map.cc', line 976
VALUE lemongraph_arcmap_has_value(VALUE self, VALUE value)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.has_value(value);
}
|
#hash ⇒ Integer
Returns the integer hash value for self.
1000 1001 1002 1003 1004 |
# File 'ext/lemongraph/arc_map.cc', line 1000
VALUE lemongraph_arcmap_hash(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.hash();
}
|
#initialize_copy(orig) ⇒ self
Method called by dup and clone methods.
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
# File 'ext/lemongraph/arc_map.cc', line 713
VALUE lemongraph_arcmap_initialize_copy(VALUE self, VALUE orig)
{
rb_call_super(1, &orig);
LemonGraph::ArcMap& from = lemongraph_arcmap_rb2ref(orig);
LemonGraph::ArcMap& to = lemongraph_arcmap_rb2ref(self);
to.initialize(self, from.graph(), from.default_value(), from.default_proc());
if (from.is_for_directed_graph()) {
for (lemon::ListDigraph::ArcIt a(lemongraph_digraph_rb2ref(from.graph())); a != lemon::INVALID; ++a) {
const LemonGraph::RBValue& v = from[a];
if (v.is_valid())
to[a] = v;
}
}
else {
for (lemon::ListGraph::ArcIt a(lemongraph_graph_rb2ref(from.graph())); a != lemon::INVALID; ++a) {
const LemonGraph::RBValue& v = from[a];
if (v.is_valid())
to[a] = v;
}
}
return self;
}
|
#length ⇒ Integer
Return the count of entries in slef for which a value has been set
841 842 843 844 845 |
# File 'ext/lemongraph/arc_map.cc', line 841
VALUE lemongraph_arcmap_length(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.length();
}
|
#values ⇒ Array<Object>
Returns an array containing all values set for arcs.
831 832 833 834 835 |
# File 'ext/lemongraph/arc_map.cc', line 831
VALUE lemongraph_arcmap_values(VALUE self)
{
LemonGraph::ArcMap& nm = lemongraph_arcmap_rb2ref(self);
return nm.values();
}
|