<commit_before>const
  WIDTH = 500
  HEIGHT = 500
  TRANSMISSION_RANGE    = 50
  INTERFERENCE_RANGE    = 100
  CARRIER_SENSING_RANGE = 120

# field state
nodes = for i til 100
  new BNode do
    Math.random! * WIDTH
    Math.random! * HEIGHT

graph = unit-disk-graph TRANSMISSION_RANGE, nodes
# remove disconnected
for n, nei of graph
  if nei.length is 0
    nodes = nodes.filter (.id is not n)
    delete graph[n]

# TODO select largest connected component
source = nodes.0

# remove disconnected from source
[btree, seen, links, max-depth] = bfs source, -> graph[it.id] ? []
nodes = nodes.filter -> seen[it.id]
for n, nei of graph
  if not seen[n]
    delete graph[n]
  else
    graph[n] = nei.filter -> seen[it.id]

# algorithm state (for step-through)
steps = []
step-idx = 0

# bind stuff
d3.select \#field
  ..select-all \.node .data nodes
    ..exit!remove!
    ..enter!append \g
      ..attr \id (.id)
      ..attr \class \node<commit_msg>Randomize node placement with random walk<commit_after>const
  WIDTH = 500
  HEIGHT = 500
  TRANSMISSION_RANGE    = 50
  INTERFERENCE_RANGE    = 100
  CARRIER_SENSING_RANGE = 120

# field state

# random walk, deflecting from boundary
nodes = let
  x = Math.random! * WIDTH
  y = Math.random! * HEIGHT

  nodes = []
  for i til 100
    if Math.random! > 0.95 and nodes.length > 1
      # restart random walk from random node instead of last
      {x, y} = nodes[Math.floor Math.random! * nodes.length]

    t = Math.random! * 2 * Math.PI
    # bias towards outer edge of transmission range
    r = Math.random! ^ 0.25 * TRANSMISSION_RANGE
    dx = r * Math.cos t ; nx = x + dx
    dy = r * Math.sin t ; ny = y + dy
    nodes.push new BNode do
      x = if nx < 0 or nx > WIDTH then x - dx else nx
      y = if ny < 0 or ny > HEIGHT then y - dy else ny

  nodes

graph = unit-disk-graph TRANSMISSION_RANGE, nodes
source = nodes.0

# remove disconnected from source
[btree, seen, links, max-depth] = bfs source, -> graph[it.id] ? []

# algorithm state (for step-through)
steps = []
step-idx = 0

# bind stuff
d3.select \#field
  ..select-all \.node .data nodes
    ..exit!remove!
    ..enter!append \g
      ..attr \id (.id)
      ..attr \class \node
{'fraction_non_alphanumeric': 0.11065573770491803, 'fraction_numerical': 0.023224043715846996, 'mean_word_length': 2.5665584415584415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '563153', 'n_tokens_mistral': 826, 'n_tokens_neox': 765, 'n_words': 261}