<commit_before>
# FIXME update to match proper spec, and include serialisation annotations
type mcd_request : record
  key : string
type mcd_reply : record
  key : string
  value : string
#
proc MCD : (type mcd_request/type mcd_reply client, [type mcd_request/type mcd_reply] backends)
  # NOTE shared dictionaries are application-level primitives we supply.
  # FIXME give type of the dictionary
  # NOTE what parameters to give e.g., whether to randomise, and initial allocation.
  global cache := empty_dictionary
#
  # Any time we get something from a backend, cache it and forward it to the
  # client.
  backends => update_cache(cache) => client
#
  # client => backends
  let request = read(client)
  if cache[request.key] = None:
    # Work out which backend memcached to forward this request to, and send.
    request => backends[hash(request.key) mod len(backends)]
  else:
    cache[request.key] => client
#
fun update_cache : (cache : type pbr_BLA, response : type mcd_reply) -> (type mcd_reply)
# FIXME relying on pass-by-reference of cache
# FIXME need array assignment syntax
#  cache[response.key] := response
  response
<commit_msg>made process body more concise;<commit_after>
# FIXME update to match proper spec, and include serialisation annotations
type mcd_request : record
  key : string
type mcd_reply : record
  key : string
  value : string
#
proc MCD : (type mcd_request/type mcd_reply client, [type mcd_request/type mcd_reply] backends)
  # NOTE shared dictionaries are application-level primitives we supply.
  # FIXME give type of the dictionary
  # NOTE what parameters to give e.g., whether to randomise, and initial allocation.
  global cache := empty_dictionary
#
  # Any time we get something from a backend, cache it and forward it to the
  # client.
  backends => update_cache(cache) => client
#
  client => test_cache_or_pass_on(client, backends)
#
fun update_cache : (cache : type pbr_BLA, response : type mcd_reply) -> (type mcd_reply)
# FIXME relying on pass-by-reference of cache
# FIXME need array assignment syntax
#  cache[response.key] := response
  response
#
fun test_cache_or_pass_on : (type mcd_request/type mcd_reply client, [type mcd_request/type mcd_reply] backend; request : type mcd_request) -> ()
  if cache[request.key] = None:
    # Work out which backend memcached to forward this request to, and send.
    request => backends[hash(request.key) mod len(backends)]
  else:
    cache[request.key] => client
{'fraction_non_alphanumeric': 0.08160779537149818, 'fraction_numerical': 0.0, 'mean_word_length': 4.253731343283582, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '6234870', 'n_tokens_mistral': 736, 'n_tokens_neox': 731, 'n_words': 279}