<commit_before>require "luarocks.loader" 
socket = require("socket")
json = require("dkjson")

local exports = {}


local function mapSeries(array, f) 
   local results = {}
   for i, v in ipairs(array) do
      local err
      err, results[i] = f(v)
      if err then
         return err, results
      end
   end
   return nil, results
end

local function emptyView(isDevice)
   return {deviceView =  isDevice, toCloud = {version = 0, values = {}},
           fromCloud =  {version = 0, values = {}}}
end

local function isEmptyView(view) 
   return (view.toCloud.version == 0) and (view.fromCloud.version == 0)
end

local function gcResponses(maps)
   local toCloud = maps.deviceView.toCloud
   local commands = toCloud and toCloud.values and toCloud.values.commands
   local lastModifVersion = commands and commands.lastModified
   local lastSeenVersion = maps.caView and maps.caView.toCloud and 
      maps.caView.toCloud.version
   if (lastSeenVersion ~= nil) and (lastModifVersion ~= nil) and
      (lastSeenVersion >= lastModifVersion) and commands.values then
      local firstIndex = commands.firstIndex or 0
      commands.firstIndex = firstIndex + #commands.values
      commands.lastModified = nil
      commands.values = {}
      return true
   end
   return false

end

local function slice(array, delta)

end

local function getCommands(maps)
   local fromCloud = maps.caView.fromCloud
   local fromCloudCommands = (fromCloud.values and fromCloud.values.commands) 
      or {}
   local toCloud = maps.deviceView.toCloud
   local toCloudCommands = (toCloud.values and toCloud.values.commands) or {}
   local firstIndex =  toCloudCommands.firstIndex or 0
   firstIndex = firstIndex + ((toCloudCommands.values and
                               #toCloudCommands.values) or 0)
   local firstIndexFromCloud = fromCloudCommands.firstIndex or 0
   local delta
   if firstIndex > firstIndexFromCloud then
      delta = firstIndex - firstIndexFromCloud
   else
      delta = 0
   end
   if fromCloudCommands.values and (#fromCloudCommands.values > delta) then
      return {firstIndex = firstIndexFromCloud + delta, 
              commands = slice(fromCloudCommands.values, delta)}
   else
      return nil
   end
end

local function addResponses(firstIndex, outputs, maps)
   local toCloud = maps.deviceView.toCloud
   toCloud.values = toCloud.values or {}
   toCloud.values.commands = toCloud.values.commands or {}
   toCloud.values.commands.firstIndex = firstIndex
   toCloud.values.commands.lastModified = toCloud.version + 1
   toCloud.values.commands.values = outputs
end

local function updateMaps(maps)
   local toCloud = maps.deviceView.toCloud;
   local fromCloud = maps.deviceView.fromCloud;
   toCloud.version = toCloud.version + 1;
   fromCloud.version = maps.caView.fromCloud.version;
end

local function syncMaps(context, spec, maps)


end<commit_msg>Add lua client 3<commit_after>require "luarocks.loader" 
socket = require("socket")
json = require("dkjson")

local exports = {}


local function mapSeries(array, f) 
   local results = {}
   for i, v in ipairs(array) do
      local err
      err, results[i] = f(v)
      if err then
         return err, results
      end
   end
   return nil, results
end

local function emptyView(isDevice)
   return {deviceView =  isDevice, toCloud = {version = 0, values = {}},
           fromCloud =  {version = 0, values = {}}}
end

local function isEmptyView(view) 
   return (view.toCloud.version == 0) and (view.fromCloud.version == 0)
end

local function gcResponses(maps)
   local toCloud = maps.deviceView.toCloud
   local commands = toCloud and toCloud.values and toCloud.values.commands
   local lastModifVersion = commands and commands.lastModified
   local lastSeenVersion = maps.caView and maps.caView.toCloud and 
      maps.caView.toCloud.version
   if (lastSeenVersion ~= nil) and (lastModifVersion ~= nil) and
      (lastSeenVersion >= lastModifVersion) and commands.values then
      local firstIndex = commands.firstIndex or 0
      commands.firstIndex = firstIndex + #commands.values
      commands.lastModified = nil
      commands.values = {}
      return true
   end
   return false
end

local function slice(array, delta)
   local res = {}
   local k = 1 
   for i = delta+1, #array do
      res[k] = array[i]
      k = k + 1
   end
   return res      
end

local function getCommands(maps)
   local fromCloud = maps.caView.fromCloud
   local fromCloudCommands = (fromCloud.values and fromCloud.values.commands) 
      or {}
   local toCloud = maps.deviceView.toCloud
   local toCloudCommands = (toCloud.values and toCloud.values.commands) or {}
   local firstIndex =  toCloudCommands.firstIndex or 0
   firstIndex = firstIndex + ((toCloudCommands.values and
                               #toCloudCommands.values) or 0)
   local firstIndexFromCloud = fromCloudCommands.firstIndex or 0
   local delta
   if firstIndex > firstIndexFromCloud then
      delta = firstIndex - firstIndexFromCloud
   else
      delta = 0
   end
   if fromCloudCommands.values and (#fromCloudCommands.values > delta) then
      return {firstIndex = firstIndexFromCloud + delta, 
              commands = slice(fromCloudCommands.values, delta)}
   else
      return nil
   end
end

local function addResponses(firstIndex, outputs, maps)
   local toCloud = maps.deviceView.toCloud
   toCloud.values = toCloud.values or {}
   toCloud.values.commands = toCloud.values.commands or {}
   toCloud.values.commands.firstIndex = firstIndex
   toCloud.values.commands.lastModified = toCloud.version + 1
   toCloud.values.commands.values = outputs
end

local function updateMaps(maps)
   local toCloud = maps.deviceView.toCloud
   local fromCloud = maps.deviceView.fromCloud
   toCloud.version = toCloud.version + 1
   fromCloud.version = maps.caView.fromCloud.version
end

local function syncMaps(context, spec, maps)


end
{'fraction_non_alphanumeric': 0.081886278515492, 'fraction_numerical': 0.004426285325161729, 'mean_word_length': 3.2541636495293265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6288022', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1715, 'n_words': 486}