Skip to content

Commit

Permalink
20477: Improves locking around entities, particularly around opcodes …
Browse files Browse the repository at this point in the history
…that do not read from two entities, unifies entity traversal code, MINOR (#153)
  • Loading branch information
howsohazard authored Jun 18, 2024
1 parent 7413d5a commit 72bd910
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 311 deletions.
6 changes: 3 additions & 3 deletions src/Amalgam/GeneralizedDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ class RepeatedGeneralizedDistanceEvaluator
//represented by precomputedRemainingIdenticalDistanceTerm
EFDT_REMAINING_IDENTICAL_PRECOMPUTED,
//everything is precomputed from interned values that are looked up
EFDT_NUMERIC_PRECOMPUTED,
EFDT_UNIVERSALLY_INTERNED_PRECOMPUTED,
//continuous without cycles, but everything is always numeric
EFDT_CONTINUOUS_UNIVERSALLY_NUMERIC,
//continuous without cycles, may contain nonnumeric data
Expand Down Expand Up @@ -1202,8 +1202,8 @@ class RepeatedGeneralizedDistanceEvaluator
return featureData[index].internedNumberIndexToNumberValue != nullptr;
}

//returns the precomputed distance term for the interned number with intern_value_index
__forceinline double ComputeDistanceTermNumberInternedPrecomputed(size_t intern_value_index, size_t index, bool high_accuracy)
//returns the precomputed distance term for the interned value with intern_value_index
__forceinline double ComputeDistanceTermInternedPrecomputed(size_t intern_value_index, size_t index, bool high_accuracy)
{
return featureData[index].internedDistanceTerms[intern_value_index].GetValue(high_accuracy);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Amalgam/SeparableBoxFilterDataStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ void SeparableBoxFilterDataStore::PopulateTargetValueAndLabelIndex(RepeatedGener
if(column_data->internedNumberValues.valueInterningEnabled)
{
if(all_values_numeric)
effective_feature_type = RepeatedGeneralizedDistanceEvaluator::EFDT_NUMERIC_PRECOMPUTED;
effective_feature_type = RepeatedGeneralizedDistanceEvaluator::EFDT_UNIVERSALLY_INTERNED_PRECOMPUTED;
else
effective_feature_type = RepeatedGeneralizedDistanceEvaluator::EFDT_CONTINUOUS_NUMERIC_PRECOMPUTED;

Expand Down
6 changes: 3 additions & 3 deletions src/Amalgam/SeparableBoxFilterDataStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ class SeparableBoxFilterDataStore
query_feature_index, high_accuracy);
}

case RepeatedGeneralizedDistanceEvaluator::EFDT_NUMERIC_PRECOMPUTED:
case RepeatedGeneralizedDistanceEvaluator::EFDT_UNIVERSALLY_INTERNED_PRECOMPUTED:
{
auto &feature_attribs = r_dist_eval.distEvaluator->featureAttribs[query_feature_index];
return r_dist_eval.ComputeDistanceTermNumberInternedPrecomputed(
return r_dist_eval.ComputeDistanceTermInternedPrecomputed(
GetValue(entity_index, feature_attribs.featureIndex).indirectionIndex, query_feature_index, high_accuracy);
}

Expand Down Expand Up @@ -791,7 +791,7 @@ class SeparableBoxFilterDataStore
auto &feature_attribs = r_dist_eval.distEvaluator->featureAttribs[query_feature_index];
auto &column_data = columnData[feature_attribs.featureIndex];
if(column_data->numberIndices.contains(entity_index))
return r_dist_eval.ComputeDistanceTermNumberInternedPrecomputed(
return r_dist_eval.ComputeDistanceTermInternedPrecomputed(
GetValue(entity_index, feature_attribs.featureIndex).indirectionIndex, query_feature_index, high_accuracy);
else
return r_dist_eval.distEvaluator->ComputeDistanceTermKnownToUnknown(query_feature_index, high_accuracy);
Expand Down
8 changes: 4 additions & 4 deletions src/Amalgam/amlg_code/full_test.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -1938,9 +1938,9 @@
(print (difference_entities "DiffEntity1" "DiffEntity2"))

(let (assoc new_entity
(call (difference_entities "DiffEntity1" "DiffEntity2") (assoc _ "DiffEntity1")))
(call (difference_entities "DiffEntity1" "DiffEntity2") (assoc _ "DiffEntity1")))
(print "new_entity: " new_entity "\n")
(print "new_entity root: " (retrieve_entity_root new_entity))
(print "new_entity root: " (retrieve_entity_root new_entity))
(print "DiffEntityChild1 root:\n" (retrieve_entity_root (list new_entity "DiffEntityChild1")))
(print "contained_entities new_entity: " (contained_entities new_entity))
(print "difference between DiffEntity2 and new_entity:\n" (difference_entities "DiffEntity2" new_entity))
Expand All @@ -1967,10 +1967,10 @@
(print (difference_entities (list "DiffContainer" "DiffEntity1") (list "DiffContainer" "DiffEntity2") ))

(let (assoc new_entity
(call (difference_entities (list "DiffContainer" "DiffEntity1") (list "DiffContainer" "DiffEntity2") )
(call (difference_entities (list "DiffContainer" "DiffEntity1") (list "DiffContainer" "DiffEntity2") )
(assoc _ (list "DiffContainer" "DiffEntity1") new_entity "DiffContainerReconstructed")))
(print "new_entity: " new_entity "\n")
(print "new_entity root: " (retrieve_entity_root new_entity))
(print "new_entity root: " (retrieve_entity_root new_entity))
(print "DiffEntityChild1 root:\n" (retrieve_entity_root (list new_entity "DiffEntityChild1")))
(print "contained_entities new_entity: " (contained_entities new_entity))
(print "difference between DiffContainer and DiffEntity2:\n" (difference_entities (list "DiffContainer" "DiffEntity2") new_entity ))
Expand Down
56 changes: 9 additions & 47 deletions src/Amalgam/amlg_code/test.amlg
Original file line number Diff line number Diff line change
@@ -1,50 +1,12 @@
(seq

(if 0 (seq
(print
(declare
{_ (null)}
(replace
_
[]
(lambda
{o 6}
)
)
)
"\n")
(conclude)
)
(create_entities "MergeEntity1" (lambda (associate "a" 3 "b" 4)) )
;(create_entities (list "MergeEntity1" "MergeEntityChild1") (lambda (associate "x" 3 "y" 4)) )
;(create_entities (list "MergeEntity1" "MergeEntityChild2") (lambda (associate "p" 3 "q" 4)) )
;(create_entities (list "MergeEntity1") (lambda (associate "E" 3 "F" 4)) )
;(create_entities (list "MergeEntity1") (lambda (associate "e" 3 "f" 4 "g" 5 "h" 6)) )

(store_entity "amlg_code/module_test_c.caml" "MergeEntity1")
(load_entity "amlg_code/module_test_c.caml" "MergeEntity1Decompressed")
(print "Compression difference: [" (difference_entities "MergeEntity1" "MergeEntity1Decompressed") "]\n")
)

(create_entities "DiffEntity1" (lambda (assoc "c" 3 "b" 4)) )
(create_entities (list "DiffEntity1" "DiffEntityChild1") (lambda (assoc "x" 3 "y" 4 "z" 6)) )
(create_entities (list "DiffEntity1" "DiffEntityChild1" "DiffEntityChild2") (lambda (assoc "p" 3 "q" 4 "u" 5 "v" 6 "w" 7)) )
(create_entities (list "DiffEntity1" "DiffEntityChild1" "DiffEntityChild2" "DiffEntityChild3") (lambda (assoc "e" 3 "p" 4 "a" 5 "o" 6 "w" 7)) )
(create_entities (list "DiffEntity1" "OnlyIn1") (lambda (assoc "m" 4)) )
(create_entities (list "DiffEntity1") (lambda (assoc "E" 3 "F" 4)) )
(create_entities (list "DiffEntity1") (lambda (assoc "e" 3 "f" 4 "g" 5 "h" 6)) )

(create_entities "DiffEntity2" (lambda (assoc "c" 3 "b" 4)) )
(create_entities (list "DiffEntity2" "DiffEntityChild1") (lambda (assoc "x" 3 "y" 4 "z" 5)) )
(create_entities (list "DiffEntity2" "DiffEntityChild1" "DiffEntityChild2") (lambda (assoc "p" 3 "q" 4 "u" 5 "v" 6 "w" 7)) )
(create_entities (list "DiffEntity2" "DiffEntityChild1" "DiffEntityChild2" "DiffEntityChild3") (lambda (assoc "e" 3 "p" 4 "a" 5 "o" 6 "w" 7)) )
(create_entities (list "DiffEntity2" "OnlyIn2") (lambda (assoc "o" 6)) )
(create_entities (list "DiffEntity2") (lambda (assoc "E" 3 "F" 4 "G" 5 "H" 6)) )
(create_entities (list "DiffEntity2") (lambda (assoc "e" 3 "f" 4)) )

(print (contained_entities "DiffEntity2"))

(print (difference_entities "DiffEntity1" "DiffEntity2"))

(let (assoc new_entity
(call (difference_entities "DiffEntity1" "DiffEntity2") (assoc _ "DiffEntity1")))
(print "new_entity: " new_entity "\n")
(print "new_entity root: " (retrieve_entity_root new_entity))
(print "DiffEntityChild1 root:\n" (retrieve_entity_root (list new_entity "DiffEntityChild1")))
(print "contained_entities new_entity: " (contained_entities new_entity))
(print "difference between DiffEntity2 and new_entity:\n" (difference_entities "DiffEntity2" new_entity))
;(print "DiffEntity2:\n" (flatten_entity "DiffEntity2"))
;(print "new_entity:\n" (flatten_entity new_entity))
)
)
76 changes: 0 additions & 76 deletions src/Amalgam/evaluablenode/EvaluableNodeTreeFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,82 +77,6 @@ std::vector<EvaluableNode *> CustomEvaluableNodeOrderedChildNodesSort(std::vecto
return list_copy_2;
}

void TraverseToEntityViaEvaluableNodeIDPath(Entity *container, EvaluableNode *id_path,
Entity *&relative_entity_container, StringInternRef &id, Entity *&relative_entity)
{
//TODO 10975: remove this function, deprecated by TraverseToEntityReferenceAndContainerViaEvaluableNodeIDPath
relative_entity_container = nullptr;
id = StringInternPool::NOT_A_STRING_ID;

if(container == nullptr)
{
relative_entity = nullptr;
return;
}

relative_entity = container;

if(EvaluableNode::IsEmptyNode(id_path))
return;

auto &ocn = id_path->GetOrderedChildNodes();

//size of the entity list excluding trailing nulls
size_t non_null_size = ocn.size();
for(; non_null_size > 0; non_null_size--)
{
if(!EvaluableNode::IsNull(ocn[non_null_size - 1]))
break;
}

if(non_null_size == 0)
{
//if empty list, return the container itself
if(id_path->GetType() == ENT_LIST)
return;

//if the string doesn't exist, then there can't be an entity with that name
id.SetIDWithReferenceHandoff(EvaluableNode::ToStringIDWithReference(id_path));

relative_entity = container->GetContainedEntity(id);
relative_entity_container = container;
return;
}

//if traversing, then it needs to be a list, otherwise not a valid entity
if(id_path->GetType() != ENT_LIST)
{
relative_entity = nullptr;
return;
}

relative_entity_container = container;

for(size_t i = 0; i < non_null_size; i++)
{
EvaluableNode *cn = ocn[i];

//null means current entity wherever it is in the traversal
if(EvaluableNode::IsNull(cn))
continue;

//if the string doesn't exist, then there can't be an entity with that name
id.SetIDWithReferenceHandoff(EvaluableNode::ToStringIDWithReference(cn));
relative_entity = relative_entity_container->GetContainedEntity(id);

//if entity doesn't exist, exit gracefully
if(relative_entity == nullptr)
return;

//if last reference, use destination type
if(i + 1 == non_null_size)
return;

//create new read lock and overwrite existing to walk down the list
relative_entity_container = relative_entity;
}
}

EvaluableNode *GetTraversalIDPathFromAToB(EvaluableNodeManager *enm, Entity *a, Entity *b)
{
//shouldn't happen, but check
Expand Down
Loading

0 comments on commit 72bd910

Please sign in to comment.