Class: LemonGraph::ArcMap

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/lemongraph/lemongraph.cc

Instance Method Summary collapse

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.

Overloads:

  • #initialize(graph, default_value = nil) ⇒ ArcMap

    Parameters:

    • graph (Graph, Digraph)

      the graph this arc map is to be bound to

    • default_value (Object) (defaults to: nil)

      the default value returned for arcs with no value.

  • #initialize(graph) {|arc, arcmap| ... } ⇒ ArcMap

    Parameters:

    • graph (Graph, Digraph)

      the graph this arc map is to be bound to

    Yield Parameters:

    Yield Returns:

    • (Object)

      the default value returned for this arc



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 (==).

Returns:

  • (Boolean)


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.

Parameters:

Returns:

  • (Object)


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.

Parameters:



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;
}

#arcsArray<Graph::Arc,Digraph::Arc>

Returns an array containing all arc keys for which a value has been set.

Returns:



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();
}

#clearself

Removes all values.

Returns:

  • (self)


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;
}

#defaultObject

Returns the default value set for this arc map.

Returns:

  • (Object)


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_procProc?

Returns the default proc set for this arc map.

Returns:

  • (Proc, nil)


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.

Parameters:

  • proc (Proc, nil)


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.

Parameters:



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_ifEnumerator

Delete entries for which the block returns a truthy value. Returns self, or, if no block is given, an Enumerator is returned.

Overloads:

  • #delete_if {|arc, value| ... } ⇒ self

    Calls the block with each arc-value pair; deletes each entry for which the block returns a truthy value; returns self

    Yield Parameters:

    Yield Returns:

    • (Boolean)

      whether to delete or not the entry

    Returns:

    • (self)
  • #delete_ifEnumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


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_pairEnumerator #each {|arc, value| ... } ⇒ self #eachEnumerator

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.

Overloads:

  • #each_pair {|arc, value| ... } ⇒ self

    Yield Parameters:

    Returns:

    • (self)
  • #each_pairEnumerator

    Returns:

    • (Enumerator)
  • #each {|arc, value| ... } ⇒ self

    Yield Parameters:

    Returns:

    • (self)
  • #eachEnumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


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_arcEnumerator

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.

Overloads:

  • #each_arc {|arc| ... } ⇒ self

    Yield Parameters:

    Returns:

    • (self)
  • #each_arcEnumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


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_pairEnumerator #each {|arc, value| ... } ⇒ self #eachEnumerator

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.

Overloads:

  • #each_pair {|arc, value| ... } ⇒ self

    Yield Parameters:

    Returns:

    • (self)
  • #each_pairEnumerator

    Returns:

    • (Enumerator)
  • #each {|arc, value| ... } ⇒ self

    Yield Parameters:

    Returns:

    • (self)
  • #eachEnumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


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_valueEnumerator

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.

Overloads:

  • #each_value {|value| ... } ⇒ self

    Yield Parameters:

    • value (Object)

    Returns:

    • (self)
  • #each_valueEnumerator

    Returns:

    • (Enumerator)

Returns:

  • (self, Enumerator)


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

Returns:

  • (Boolean)


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();
}

#graphGraph, Digraph

Returns the graph this arc map is related to.

Returns:



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.

Parameters:

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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);
}

#hashInteger

Returns the integer hash value for self.

Returns:

  • (Integer)


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.

Returns:

  • (self)


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;
}

#lengthInteger

Return the count of entries in slef for which a value has been set

Returns:

  • (Integer)


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();
}

#valuesArray<Object>

Returns an array containing all values set for arcs.

Returns:

  • (Array<Object>)


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();
}