<commit_before>require 'rubygems'
require 'bud'

module TokenRing
  state do
    table :next_node, [] => [:addr]
    channel :token, [:@loc]
    table :token_persist, [:loc]
  end

  bloom :make_ring do
    initial_data <= node do |n|
      # Calculate the successor node
      succ_id = (n.uid + 1) % node_count[[]].num
      succ_addr = [node[[succ_id]].addr]
      [n.uid, :next_node, [succ_addr]]
    end

    # The deployer sends an initial message to the node with ID 0
    token <~ (node_ready * node).rights do |n|
      [n.addr] if (@options[:deploy] and n.uid == 0)
    end
  end

  bloom :pass_token do
    # Persist the token for as long as necessary
    token_persist <= token
    token_persist <- (token_persist * next_node).lefts
    # Pass on the token
    token <~ (token_persist * next_node).pairs {[next_node[[]].addr]}
    stdio <~ token {["#{ip_port}: Got token!"]}
  end
end
<commit_msg>Code cleanup for tokenring.<commit_after>require 'rubygems'
require 'bud'

module TokenRing
  state do
    table :next_node, [] => [:addr]
    channel :token, [:@loc]
    table :token_persist, [:loc]
  end

  bloom :make_ring do
    initial_data <= node do |n|
      # Calculate the successor node
      succ_id = (n.uid + 1) % node_count[[]].num
      succ_addr = [node[[succ_id]].addr]
      [n.uid, :next_node, [succ_addr]]
    end

    # The deployer sends an initial message to the node with ID 0
    token <~ (node_ready * node).rights do |n|
      [n.addr] if (@options[:deploy] and n.uid == 0)
    end
  end

  bloom :pass_token do
    # Persist the token for as long as necessary
    token_persist <= token
    token_persist <- (token_persist * next_node).lefts
    # Pass on the token
    token <~ (token_persist * next_node).pairs do |tp, nn|
      [nn.addr]
    end
  end

  bloom :print_token do
    stdio <~ token {["#{ip_port}: Got token!"]}
  end
end

{'fraction_non_alphanumeric': 0.12739872068230276, 'fraction_numerical': 0.0031982942430703624, 'mean_word_length': 2.878099173553719, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690110', 'n_tokens_mistral': 690, 'n_tokens_neox': 658, 'n_words': 201}