From 83a0ea2772904040c06e37962f1f0d708675367c Mon Sep 17 00:00:00 2001 From: yui-knk Date: Tue, 21 Jan 2025 12:13:44 +0900 Subject: [PATCH] More explanation for Digraph algorithm --- lib/lrama/digraph.rb | 24 +++++++++++++++++++++--- sig/generated/lrama/digraph.rbs | 24 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/lrama/digraph.rb b/lib/lrama/digraph.rb index 2161f304..6c4d2c50 100644 --- a/lib/lrama/digraph.rb +++ b/lib/lrama/digraph.rb @@ -2,10 +2,28 @@ # frozen_string_literal: true module Lrama - # Algorithm Digraph of https://dl.acm.org/doi/pdf/10.1145/69622.357187 (P. 625) + # Digraph Algorithm of https://dl.acm.org/doi/pdf/10.1145/69622.357187 (P. 625) # - # @rbs generic X < Object -- Type of a member of `sets` - # @rbs generic Y < _Or -- Type of sets assigned to a member of `sets` + # Digraph is an algorithm for graph data structure. + # The algorithm efficiently traverses SCC (Strongly Connected Component) of graph + # and merges nodes attributes within the same SCC. + # + # `compute_read_sets` and `compute_follow_sets` have the same structure. + # Graph of gotos and attributes of gotos are given then compute propagated attributes for each node. + # In the case of `compute_read_sets`: + # + # * Set of gotos is nodes of graph + # * `reads_relation` is edges of graph + # * `direct_read_sets` is nodes attributes + # + # In the case of `compute_follow_sets`: + # * Set of gotos is nodes of graph + # * `includes_relation` is edges of graph + # * `read_sets` is nodes attributes + # + # + # @rbs generic X < Object -- Type of a node + # @rbs generic Y < _Or -- Type of attribute sets assigned to a node which should support merge operaiton (#| method) class Digraph # TODO: rbs-inline 0.10.0 doesn't support instance variables. # Move these type declarations above instance variable definitions, once it's supported. diff --git a/sig/generated/lrama/digraph.rbs b/sig/generated/lrama/digraph.rbs index d27a4660..7e36513e 100644 --- a/sig/generated/lrama/digraph.rbs +++ b/sig/generated/lrama/digraph.rbs @@ -1,10 +1,28 @@ # Generated from lib/lrama/digraph.rb with RBS::Inline module Lrama - # Algorithm Digraph of https://dl.acm.org/doi/pdf/10.1145/69622.357187 (P. 625) + # Digraph Algorithm of https://dl.acm.org/doi/pdf/10.1145/69622.357187 (P. 625) # - # @rbs generic X < Object -- Type of a member of `sets` - # @rbs generic Y < _Or -- Type of sets assigned to a member of `sets` + # Digraph is an algorithm for graph data structure. + # The algorithm efficiently traverses SCC (Strongly Connected Component) of graph + # and merges nodes attributes within the same SCC. + # + # `compute_read_sets` and `compute_follow_sets` have the same structure. + # Graph of gotos and attributes of gotos are given then compute propagated attributes for each node. + # In the case of `compute_read_sets`: + # + # * Set of gotos is nodes of graph + # * `reads_relation` is edges of graph + # * `direct_read_sets` is nodes attributes + # + # In the case of `compute_follow_sets`: + # * Set of gotos is nodes of graph + # * `includes_relation` is edges of graph + # * `read_sets` is nodes attributes + # + # + # @rbs generic X < Object -- Type of a node + # @rbs generic Y < _Or -- Type of attribute sets assigned to a node which should support merge operaiton (#| method) class Digraph[X < Object, Y < _Or] interface _Or def |: (self) -> self