Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate digraph type declarations to rbs-inline #515

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading