Class: LemonGraph::GraphItem

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/lemongraph/graph_item.cc,
ext/lemongraph/lemongraph.cc

Overview

Base class for nodes, arcs and edges of directed or undirected graphs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#graphDigraph, Graph (readonly)

Returns the graph the item belongs to.

Returns:

#idInteger (readonly)

Returns the graph item's id.

Returns:

  • (Integer)

    the graph item's id

Instance Method Details

#!=(other) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
# File 'ext/lemongraph/graph_item.cc', line 56

VALUE lemongraph_graphitem_is_notequal(VALUE self, VALUE other)
{
  if (rb_class_of(other) != rb_class_of(self))
    return Qtrue;
  return ((rb_iv_get(self, "@id") != rb_iv_get(other, "@id")) || (rb_iv_get(self, "@graph") != rb_iv_get(other, "@graph"))) ? Qtrue : Qfalse;
}

#<=>(other) ⇒ Boolean?

Compare self with another graph item. Returns nil if other and self do not have the same class, else returns self.id <=> other.id.

Parameters:

Returns:

  • (Boolean, nil)


69
70
71
72
73
74
# File 'ext/lemongraph/graph_item.cc', line 69

VALUE lemongraph_graphitem_compare(VALUE self, VALUE other)
{
  if (rb_class_of(other) != rb_class_of(self) || rb_iv_get(self, "@graph") != rb_iv_get(other, "@graph"))
    return Qnil;
  return rb_funcall(rb_iv_get(self, "@id"), id_comp, 1, rb_iv_get(other, "@id"));
}

#==(other) ⇒ Boolean

Returns true if other has the same class as self and self and other share the same graph and id.

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'ext/lemongraph/graph_item.cc', line 46

VALUE lemongraph_graphitem_is_equal(VALUE self, VALUE other)
{
  if (rb_class_of(other) != rb_class_of(self))
    return Qfalse;
  return ((rb_iv_get(self, "@id") == rb_iv_get(other, "@id")) && (rb_iv_get(self, "@graph") == rb_iv_get(other, "@graph"))) ? Qtrue : Qfalse;
}