Class: Kibuvits_krl171bt4_graph_vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/kibuvits_ruby_library_krl171bt4_.rb

Overview

A useful hint:

Hyperedges (http://urls.softf1.com/a1/krl/frag3/ )
can be implemented by using a vertex in place of
a hyperedge and furnishing all vertices with
a type parameter that distinguishes plain vertices
from hyperedge vertices.

The current implementation uses only directed edges. The edge records are stored in vertices that connect to the arrow tail side of an edge.

Constant Summary collapse

@@ar_lc_modes =

The specification, where hyperedges, edges in general, were instances of a separate class, is considered unpractical to the point of being flawed, because after the completion of vertex and edge class that conform with that kind of a specification, it turned out that the client code is far more complex than it could be with the implementation that has the comment that You are just reading.

[$kibuvits_krl171bt4_lc_any, $kibuvits_krl171bt4_lc_outbound, $kibuvits_krl171bt4_lc_inbound]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(b_threadsafe = true) ⇒ Kibuvits_krl171bt4_graph_vertex




10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10233

def initialize b_threadsafe=true
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, [FalseClass,TrueClass],b_threadsafe
   end # if
   @s_id=Kibuvits_krl171bt4_GUID_generator.generate_GUID.freeze
   @ht_vertex_records=Hash.new
   @ht_edge_records=Hash.new
   @ht_inbound_vertices=Hash.new
   @ht_outbound_vertices=Hash.new
   @ht_all_vertices=Hash.new
   @s_connections_state_ID=Kibuvits_krl171bt4_GUID_generator.generate_GUID
   @b_threadsafe=b_threadsafe
   @mx=nil
   @mx=Monitor.new if b_threadsafe
end

Instance Attribute Details

#ht_all_verticesObject (readonly)

key — vertex ID value — vertex It duplicates the conjunction of the ht_inbound_vertices and the ht_outbound_vertices, but its useful for efficiency.



10222
10223
10224
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10222

def ht_all_vertices
  @ht_all_vertices
end

#ht_edge_recordsObject (readonly)

key — outbound vertex ID value — a hashtable, Hash instance

The current implementation uses only directed edges. The edge records are stored in vertices that connect to the arrow tail side of an edge.



10192
10193
10194
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10192

def ht_edge_records
  @ht_edge_records
end

#ht_inbound_verticesObject (readonly)

key — vertex ID value — vertex An inbound vertex is a vertex that is connected to the current vertex by a directed edge so that the directed edge leaves the inbound vertex and arrives to the current vertex.

Due to consistency reasons the content of this hashtable must not be modified by



10203
10204
10205
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10203

def ht_inbound_vertices
  @ht_inbound_vertices
end

#ht_outbound_verticesObject (readonly)

key — vertex ID value — vertex An outbound vertex is a vertex that is connected to the current vertex by a directed edge so that the directed edge leaves the current vertex and arrives to the outbound vertex.

The edge records of the outbound vertices are held in the current vertex.



10214
10215
10216
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10214

def ht_outbound_vertices
  @ht_outbound_vertices
end

#ht_vertex_recordsObject (readonly)

Data that is attached to this vertex.



10184
10185
10186
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10184

def ht_vertex_records
  @ht_vertex_records
end

#s_connections_state_IDObject (readonly)

The @s_connections_state_ID is a GUID that is changed every time any vertices are added or removed from the graph. It simplifies the code of graph-crawling spiders that want to find out, wether any vertices have been added or removed after the last time the spider visited the vertex.



10229
10230
10231
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10229

def s_connections_state_ID
  @s_connections_state_ID
end

#s_idObject (readonly)

Returns the value of attribute s_id.



10181
10182
10183
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10181

def s_id
  @s_id
end

Instance Method Details

#connect_inbound_vertex(ob_vertex) ⇒ Object

It’s OK for a vertex to be connected to itself, however, this method will throw on an attempt to add the same directed edge more than once.



10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10394

def connect_inbound_vertex(ob_vertex)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_graph_vertex, ob_vertex
   end # if KIBUVITS_krl171bt4_b_DEBUG
   if @b_threadsafe
      @mx.synchronize do
         connect_inbound_vertex_semilockless(ob_vertex)
      end # block
   else
      connect_inbound_vertex_semilockless(ob_vertex)
   end # if
end

#connect_outbound_vertex(ob_vertex) ⇒ Object

It’s OK for a vertex to be connected to itself, however, this method will throw on an attempt to add the same directed edge more than once.



10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10377

def connect_outbound_vertex(ob_vertex)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_graph_vertex, ob_vertex
   end # if KIBUVITS_krl171bt4_b_DEBUG
   if @b_threadsafe
      @mx.synchronize do
         connect_outbound_vertex_semilockless(ob_vertex)
      end # block
   else
      connect_outbound_vertex_semilockless(ob_vertex)
   end # if
end

#connected?(ob_vertex, s_mode = $kibuvits_krl171bt4_lc_any) ⇒ Boolean

s_mode is from the set “any”,“inbound”,“outbound”

Returns:

  • (Boolean)


10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10251

def connected?(ob_vertex,s_mode=$kibuvits_krl171bt4_lc_any)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_graph_vertex, ob_vertex
      kibuvits_krl171bt4_assert_is_among_values(bn,@@ar_lc_modes,s_mode)
   end # if
   b_out=false
   case s_mode
   when $kibuvits_krl171bt4_lc_any
      b_out=@ht_all_vertices.has_key?(ob_vertex.s_id)
   when $kibuvits_krl171bt4_lc_outbound
      b_out=@ht_outbound_vertices.has_key?(ob_vertex.s_id)
   when $kibuvits_krl171bt4_lc_inbound
      b_out=@ht_inbound_vertices.has_key?(ob_vertex.s_id)
   else
      bn=binding()
      kibuvits_krl171bt4_assert_is_among_values(bn,@@ar_lc_modes,s_mode)
   end # case s_mode
   return b_out
end

#disconnect_all_verticesObject



10454
10455
10456
10457
10458
10459
10460
10461
10462
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10454

def disconnect_all_vertices
   if @b_threadsafe
      @mx.synchronize do
         disconnect_all_vertices_semilockless()
      end # block
   else
      disconnect_all_vertices_semilockless()
   end # if
end

#disconnect_vertex(ob_vertex) ⇒ Object



10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10439

def disconnect_vertex(ob_vertex)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_typecheck bn, Kibuvits_krl171bt4_graph_vertex, ob_vertex
   end # if KIBUVITS_krl171bt4_b_DEBUG
   if @b_threadsafe
      @mx.synchronize do
         disconnect_vertex_semilockless(ob_vertex)
      end # block
   else
      disconnect_vertex_semilockless(ob_vertex)
   end # if
end

#i_degree(s_mode = $kibuvits_krl171bt4_lc_any) ⇒ Object

mathworld.wolfram.com/VertexDegree.html

The current implementation returns 0, if the vertex is connected only to itself.



10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
# File 'lib/kibuvits_ruby_library_krl171bt4_.rb', line 10276

def i_degree(s_mode=$kibuvits_krl171bt4_lc_any)
   if KIBUVITS_krl171bt4_b_DEBUG
      bn=binding()
      kibuvits_krl171bt4_assert_is_among_values(bn,@@ar_lc_modes,s_mode)
   end # if
   i_out=0
   case s_mode
   when $kibuvits_krl171bt4_lc_any
      if @b_threadsafe
         @mx.synchronize do
            i_out=@ht_outbound_vertices.length+
            @ht_inbound_vertices.length
            i_out=i_out-1 if @ht_inbound_vertices.has_key? @s_id
            i_out=i_out-1 if @ht_outbound_vertices.has_key? @s_id
         end # block
      else
         i_out=@ht_outbound_vertices.length+
         @ht_inbound_vertices.length
         i_out=i_out-1 if @ht_inbound_vertices.has_key? @s_id
         i_out=i_out-1 if @ht_outbound_vertices.has_key? @s_id
      end # if
   when $kibuvits_krl171bt4_lc_outbound
      if @b_threadsafe
         @mx.synchronize do
            i_out=@ht_outbound_vertices.length
            i_out=i_out-1 if @ht_outbound_vertices.has_key? @s_id
         end # block
      else
         i_out=@ht_outbound_vertices.length
         i_out=i_out-1 if @ht_outbound_vertices.has_key? @s_id
      end # if
   when $kibuvits_krl171bt4_lc_inbound
      if @b_threadsafe
         @mx.synchronize do
            i_out=@ht_inbound_vertices.length
            i_out=i_out-1 if @ht_inbound_vertices.has_key? @s_id
         end # block
      else
         i_out=@ht_inbound_vertices.length
         i_out=i_out-1 if @ht_inbound_vertices.has_key? @s_id
      end # if
   else
      bn=binding()
      kibuvits_krl171bt4_assert_is_among_values(bn,@@ar_lc_modes,s_mode)
   end # case s_mode
   return i_out
end