Skip to content

Commit

Permalink
check hashes only for needed example
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyz4k committed Jul 7, 2021
1 parent d526a75 commit 81f50a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/pattern_matching/aux_value.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unpack_value(p::AuxValue) = isa(p.value, Matcher) ? [] : unpack_value(p.value)
unwrap_matcher(p::AuxValue) = [p.value]


_update_value(data::TaskData, value, current_value::AuxValue) = _update_value(data, value, current_value.value)
_update_value(data::TaskData, example_num, value, current_value::AuxValue) = _update_value(data, example_num, value, current_value.value)

function _drop_hashes(data::AuxValue, hashes)
modified, effective, mod_hashes = _drop_hashes(data.value, hashes)
Expand Down
28 changes: 17 additions & 11 deletions src/pattern_matching/either.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,42 @@ update_value(data::TaskData, path_keys::Array, value::Either, current_value::Eit
invoke(update_value, Tuple{TaskData,Array,Any,Any}, data, path_keys, value, current_value)

function update_value(data::TaskData, path_keys::Array, value, current_value::Either)::TaskData
data = _update_value(data, value, current_value)
data = _update_value(data, path_keys[2], value, current_value)
return invoke(update_value, Tuple{TaskData,Array,Any,Any}, data, path_keys, value, current_value)
end

function _update_value(data::TaskData, value, current_value::Either)::TaskData
function _update_value(data::TaskData, example_num, value, current_value::Either)::TaskData
hashes_to_del = Set()
matched_options = []
for option in current_value.options
if isnothing(common_value(value, option.value))
if !isnothing(option.option_hash)
hashes_to_del = Set([option.option_hash])
while !isempty(hashes_to_del)
data, hashes_to_del = drop_hashes(data, hashes_to_del)
end
push!(hashes_to_del, option.option_hash)
end
else
data = _update_value(data, value, option.value)
push!(matched_options, option)
end
end
while !isempty(hashes_to_del)
data, hashes_to_del = drop_hashes(data, example_num, hashes_to_del)
end
for option in matched_options
data = _update_value(data, example_num, value, option.value)
end
return data
end

_update_value(data::TaskData, value, current_value) = data
_update_value(data::TaskData, example_num, value, current_value) = data


function drop_hashes(data::TaskData, hashes)
function drop_hashes(data::TaskData, example_num, hashes)
data = copy(data)
new_hashes = Set()
for (key, value) in data
modified, effective, mod_hashes = _drop_hashes(value, hashes)
modified, effective, mod_hashes = _drop_hashes(value[example_num], hashes)
if effective
data[key] = modified
data[key] = copy(value)
data[key][example_num] = modified
union!(new_hashes, mod_hashes)
end
end
Expand Down

0 comments on commit 81f50a8

Please sign in to comment.