Skip to content

Commit

Permalink
Merge pull request ruby#515 from yui-knk/migrate_digraph_rbs_inline
Browse files Browse the repository at this point in the history
Migrate digraph type declarations to rbs-inline
  • Loading branch information
yui-knk authored Jan 20, 2025
2 parents 83e320a + 40e6f1b commit b042b29
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
30 changes: 30 additions & 0 deletions lib/lrama/digraph.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
# rbs_inline: enabled
# frozen_string_literal: true

module Lrama
# Algorithm Digraph 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`
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.
#
# @rbs!
# interface _Or
# def |: (self) -> self
# end
# @sets: Array[X]
# @relation: Hash[X, Array[X]]
# @base_function: Hash[X, Y]
# @stack: Array[X]
# @h: Hash[X, (Integer|Float)?]
# @result: Hash[X, Y]

# @rbs sets: Array[X]
# @rbs relation: Hash[X, Array[X]]
# @rbs base_function: Hash[X, Y]
# @rbs return: void
def initialize(sets, relation, base_function)

# X in the paper
@sets = sets

# R in the paper
@relation = relation

# F' in the paper
@base_function = base_function

# S in the paper
@stack = []

# N in the paper
@h = Hash.new(0)

# F in the paper
@result = {}
end

# @rbs () -> Hash[X, Y]
def compute
@sets.each do |x|
next if @h[x] != 0
Expand All @@ -29,6 +58,7 @@ def compute

private

# @rbs (X x) -> void
def traverse(x)
@stack.push(x)
d = @stack.count
Expand Down
39 changes: 39 additions & 0 deletions sig/generated/lrama/digraph.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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)
#
# @rbs generic X < Object -- Type of a member of `sets`
# @rbs generic Y < _Or -- Type of sets assigned to a member of `sets`
class Digraph[X < Object, Y < _Or]
interface _Or
def |: (self) -> self
end

@sets: Array[X]

@relation: Hash[X, Array[X]]

@base_function: Hash[X, Y]

@stack: Array[X]

@h: Hash[X, (Integer | Float)?]

@result: Hash[X, Y]

# @rbs sets: Array[X]
# @rbs relation: Hash[X, Array[X]]
# @rbs base_function: Hash[X, Y]
# @rbs return: void
def initialize: (Array[X] sets, Hash[X, Array[X]] relation, Hash[X, Y] base_function) -> void

# @rbs () -> Hash[X, Y]
def compute: () -> Hash[X, Y]

private

# @rbs (X x) -> void
def traverse: (X x) -> void
end
end
23 changes: 0 additions & 23 deletions sig/lrama/digraph.rbs

This file was deleted.

0 comments on commit b042b29

Please sign in to comment.