From a12e82765f4998a00a28276b86181ba45e11d20f Mon Sep 17 00:00:00 2001 From: howsohazard <143410553+howsohazard@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:23:21 -0400 Subject: [PATCH] 21174: Fixes potential segfaults and code cleanup (#215) --- src/Amalgam/SBFDSColumnData.h | 4 +- src/Amalgam/SeparableBoxFilterDataStore.cpp | 23 +++---- src/Amalgam/SeparableBoxFilterDataStore.h | 66 +++++++++---------- src/Amalgam/entity/Entity.cpp | 12 ++-- src/Amalgam/entity/EntityQueries.h | 3 + src/Amalgam/entity/EntityQueryCaches.cpp | 8 +-- src/Amalgam/evaluablenode/EvaluableNode.h | 2 +- .../evaluablenode/EvaluableNodeManagement.h | 12 ++-- .../interpreter/InterpreterOpcodesBase.cpp | 14 ++-- .../InterpreterOpcodesDataTypes.cpp | 8 +-- .../InterpreterOpcodesEntityAccess.cpp | 4 +- .../interpreter/InterpreterOpcodesMath.cpp | 4 +- .../InterpreterOpcodesTransformations.cpp | 4 +- 13 files changed, 84 insertions(+), 80 deletions(-) diff --git a/src/Amalgam/SBFDSColumnData.h b/src/Amalgam/SBFDSColumnData.h index 48a3a7ef..bdb5feb4 100644 --- a/src/Amalgam/SBFDSColumnData.h +++ b/src/Amalgam/SBFDSColumnData.h @@ -1347,7 +1347,7 @@ class SBFDSColumnData //returns true if the value is equal to notAValue //note that this is a method due to not-a-number being treated as not equal to itself - constexpr bool IsNotAValue(ValueType value) + __forceinline bool IsNotAValue(ValueType value) { if constexpr(std::is_same_v) return FastIsNaN(value); @@ -1360,6 +1360,8 @@ class SBFDSColumnData { if constexpr(std::is_same_v) return std::numeric_limits::quiet_NaN(); + else if constexpr(std::is_same_v) + return string_intern_pool.NOT_A_STRING_ID; else return ValueType(); }(); diff --git a/src/Amalgam/SeparableBoxFilterDataStore.cpp b/src/Amalgam/SeparableBoxFilterDataStore.cpp index 1f9c7f12..c0a802fc 100644 --- a/src/Amalgam/SeparableBoxFilterDataStore.cpp +++ b/src/Amalgam/SeparableBoxFilterDataStore.cpp @@ -133,7 +133,7 @@ void SeparableBoxFilterDataStore::RemoveColumnIndex(size_t column_index_to_remov //will replace the values at index_to_remove with the values at index_to_move size_t column_index_to_move = columnData.size() - 1; - size_t label_id = columnData[column_index_to_remove]->stringId; + StringInternPool::StringID label_id = columnData[column_index_to_remove]->stringId; size_t num_columns = columnData.size(); @@ -144,7 +144,7 @@ void SeparableBoxFilterDataStore::RemoveColumnIndex(size_t column_index_to_remov matrix[i * num_columns + column_index_to_remove] = matrix[i * num_columns + column_index_to_move]; //update column lookup - size_t label_id_to_move = columnData[column_index_to_move]->stringId; + StringInternPool::StringID label_id_to_move = columnData[column_index_to_move]->stringId; labelIdToColumnIndex[label_id_to_move] = column_index_to_remove; //rearrange columns @@ -369,7 +369,8 @@ void SeparableBoxFilterDataStore::UpdateEntityLabel(Entity *entity, size_t entit // and sets distances_out to the found entities. Infinity is allowed to compute all distances. //if enabled_indices is not nullptr, it will only find distances to those entities, and it will modify enabled_indices in-place // removing entities that do not have the corresponding labels -void SeparableBoxFilterDataStore::FindEntitiesWithinDistance(GeneralizedDistanceEvaluator &dist_eval, std::vector &position_label_ids, +void SeparableBoxFilterDataStore::FindEntitiesWithinDistance(GeneralizedDistanceEvaluator &dist_eval, + std::vector &position_label_sids, std::vector &position_values, std::vector &position_value_types, double max_dist, StringInternPool::StringID radius_label, BitArrayIntegerSet &enabled_indices, std::vector> &distances_out) @@ -381,7 +382,7 @@ void SeparableBoxFilterDataStore::FindEntitiesWithinDistance(GeneralizedDistance r_dist_eval.distEvaluator = &dist_eval; //look up these data structures upfront for performance - PopulateTargetValuesAndLabelIndices(r_dist_eval, position_label_ids, position_values, position_value_types); + PopulateTargetValuesAndLabelIndices(r_dist_eval, position_label_sids, position_values, position_value_types); bool high_accuracy = dist_eval.highAccuracyDistances; double max_dist_exponentiated = dist_eval.ExponentiateDifferenceTerm(max_dist, high_accuracy); @@ -531,7 +532,7 @@ void SeparableBoxFilterDataStore::FindEntitiesWithinDistance(GeneralizedDistance } void SeparableBoxFilterDataStore::FindEntitiesNearestToIndexedEntity(GeneralizedDistanceEvaluator &dist_eval, - std::vector &position_label_ids, size_t search_index, + std::vector &position_label_sids, size_t search_index, size_t top_k, StringInternPool::StringID radius_label, BitArrayIntegerSet &enabled_indices, bool expand_to_first_nonzero_distance, std::vector> &distances_out, size_t ignore_index, RandomStream rand_stream) { @@ -548,7 +549,7 @@ void SeparableBoxFilterDataStore::FindEntitiesNearestToIndexedEntity(Generalized r_dist_eval.featureData.resize(num_enabled_features); for(size_t i = 0; i < num_enabled_features; i++) { - auto found = labelIdToColumnIndex.find(position_label_ids[i]); + auto found = labelIdToColumnIndex.find(position_label_sids[i]); if(found == end(labelIdToColumnIndex)) continue; @@ -713,7 +714,7 @@ void SeparableBoxFilterDataStore::FindEntitiesNearestToIndexedEntity(Generalized } void SeparableBoxFilterDataStore::FindNearestEntities(GeneralizedDistanceEvaluator &dist_eval, - std::vector &position_label_ids, std::vector &position_values, + std::vector &position_label_sids, std::vector &position_values, std::vector &position_value_types, size_t top_k, StringInternPool::StringID radius_label, size_t ignore_entity_index, BitArrayIntegerSet &enabled_indices, std::vector> &distances_out, RandomStream rand_stream) @@ -725,7 +726,7 @@ void SeparableBoxFilterDataStore::FindNearestEntities(GeneralizedDistanceEvaluat r_dist_eval.distEvaluator = &dist_eval; //look up these data structures upfront for performance - PopulateTargetValuesAndLabelIndices(r_dist_eval, position_label_ids, position_values, position_value_types); + PopulateTargetValuesAndLabelIndices(r_dist_eval, position_label_sids, position_values, position_value_types); enabled_indices.erase(ignore_entity_index); @@ -959,7 +960,7 @@ void SeparableBoxFilterDataStore::VerifyAllEntitiesForColumn(size_t column_index if(feature_type == ENIVT_STRING_ID_INDIRECTION_INDEX && feature_value.indirectionIndex != 0) { auto feature_value_resolved = column_data->GetResolvedValue(feature_type, feature_value); - assert(feature_value_resolved.stringID != string_intern_pool.EMPTY_STRING_ID); + assert(feature_value_resolved.stringID != string_intern_pool.NOT_A_STRING_ID); } } } @@ -976,13 +977,13 @@ void SeparableBoxFilterDataStore::DeleteEntityIndexFromColumns(size_t entity_ind } } -size_t SeparableBoxFilterDataStore::AddLabelsAsEmptyColumns(std::vector &label_ids, size_t num_entities) +size_t SeparableBoxFilterDataStore::AddLabelsAsEmptyColumns(std::vector &label_sids, size_t num_entities) { size_t num_existing_columns = columnData.size(); size_t num_inserted_columns = 0; //create columns for the labels, don't count any that already exist - for(auto label_id : label_ids) + for(auto label_id : label_sids) { auto [_, inserted] = labelIdToColumnIndex.insert(std::make_pair(label_id, columnData.size())); if(inserted) diff --git a/src/Amalgam/SeparableBoxFilterDataStore.h b/src/Amalgam/SeparableBoxFilterDataStore.h index e8801d40..be2d778e 100644 --- a/src/Amalgam/SeparableBoxFilterDataStore.h +++ b/src/Amalgam/SeparableBoxFilterDataStore.h @@ -108,7 +108,7 @@ class SeparableBoxFilterDataStore } //returns true if the structure already has the label - inline bool DoesHaveLabel(size_t label_id) + inline bool DoesHaveLabel(StringInternPool::StringID label_id) { return (labelIdToColumnIndex.count(label_id) > 0); } @@ -128,14 +128,14 @@ class SeparableBoxFilterDataStore } //expand the structure by adding a new column/label/feature and populating with data from entities - void AddLabels(std::vector &label_ids, const std::vector &entities) + void AddLabels(std::vector &label_sids, const std::vector &entities) { //make sure have data to add - if(label_ids.size() == 0 || entities.size() == 0) + if(label_sids.size() == 0 || entities.size() == 0) return; //resize the matrix and populate column and label_id lookups - size_t num_columns_added = AddLabelsAsEmptyColumns(label_ids, entities.size()); + size_t num_columns_added = AddLabelsAsEmptyColumns(label_sids, entities.size()); size_t num_columns = columnData.size(); size_t num_previous_columns = columnData.size() - num_columns_added; @@ -223,9 +223,9 @@ class SeparableBoxFilterDataStore return columnData[column_index]->stringIdIndices; } - //given a feature_id and a range [low, high], fills out with all the entities with values of feature feature_id within specified range + //given a feature_id and a range [low, high], fills out with all the entities with values of feature feature_sid within specified range //if the feature value is null, it will NOT be present in the search results, ie "x" != 3 will NOT include elements with x is null, even though null != 3 - inline void FindAllEntitiesWithinRange(size_t feature_id, EvaluableNodeImmediateValueType value_type, + inline void FindAllEntitiesWithinRange(StringInternPool::StringID feature_sid, EvaluableNodeImmediateValueType value_type, EvaluableNodeImmediateValue &low, EvaluableNodeImmediateValue &high, BitArrayIntegerSet &out, bool between_values = true) { if(numEntities == 0) @@ -234,7 +234,7 @@ class SeparableBoxFilterDataStore return; } - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) { out.clear(); @@ -245,7 +245,7 @@ class SeparableBoxFilterDataStore } //sets out to include only entities that have the given feature - inline void FindAllEntitiesWithFeature(size_t feature_id, BitArrayIntegerSet &out) + inline void FindAllEntitiesWithFeature(StringInternPool::StringID feature_sid, BitArrayIntegerSet &out) { if(numEntities == 0) { @@ -253,7 +253,7 @@ class SeparableBoxFilterDataStore return; } - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) { out.clear(); @@ -266,7 +266,7 @@ class SeparableBoxFilterDataStore //filters out to include only entities that have the given feature //if in_batch is true, will update out in batch for performance, //meaning its number of elements will need to be updated - inline void IntersectEntitiesWithFeature(size_t feature_id, BitArrayIntegerSet &out, bool in_batch) + inline void IntersectEntitiesWithFeature(StringInternPool::StringID feature_sid, BitArrayIntegerSet &out, bool in_batch) { if(numEntities == 0) { @@ -274,7 +274,7 @@ class SeparableBoxFilterDataStore return; } - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) { out.clear(); @@ -286,13 +286,13 @@ class SeparableBoxFilterDataStore //sets out to include only entities that have the given feature and records the values into // entities and values respectively. enabled_entities is used as a buffer - inline void FindAllEntitiesWithValidNumbers(size_t feature_id, BitArrayIntegerSet &enabled_entities, + inline void FindAllEntitiesWithValidNumbers(StringInternPool::StringID feature_sid, BitArrayIntegerSet &enabled_entities, std::vector &entities, std::vector &values) { if(numEntities == 0) return; - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) return; size_t column_index = column->second; @@ -315,13 +315,13 @@ class SeparableBoxFilterDataStore //filters enabled_indices to include only entities that have the given feature // records the entities into entities and values respectively - inline void IntersectEntitiesWithValidNumbers(size_t feature_id, BitArrayIntegerSet &enabled_entities, + inline void IntersectEntitiesWithValidNumbers(StringInternPool::StringID feature_sid, BitArrayIntegerSet &enabled_entities, std::vector &entities, std::vector &values) { if(numEntities == 0) return; - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) return; size_t column_index = column->second; @@ -343,7 +343,7 @@ class SeparableBoxFilterDataStore } //sets out to include only entities that don't have the given feature - inline void FindAllEntitiesWithoutFeature(size_t feature_id, BitArrayIntegerSet &out) + inline void FindAllEntitiesWithoutFeature(StringInternPool::StringID feature_sid, BitArrayIntegerSet &out) { if(numEntities == 0) { @@ -351,7 +351,7 @@ class SeparableBoxFilterDataStore return; } - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) { out.clear(); @@ -364,23 +364,23 @@ class SeparableBoxFilterDataStore //filters out to include only entities that don't have the given feature //if in_batch is true, will update out in batch for performance, //meaning its number of elements will need to be updated - inline void IntersectEntitiesWithoutFeature(size_t feature_id, BitArrayIntegerSet &out, bool in_batch) + inline void IntersectEntitiesWithoutFeature(StringInternPool::StringID feature_sid, BitArrayIntegerSet &out, bool in_batch) { if(numEntities == 0) return; - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) return; columnData[column->second]->invalidIndices.IntersectTo(out, in_batch); } - //given a feature_id, value_type, and value, inserts into out all the entities that have the value - inline void UnionAllEntitiesWithValue(size_t feature_id, + //given a feature_sid, value_type, and value, inserts into out all the entities that have the value + inline void UnionAllEntitiesWithValue(StringInternPool::StringID feature_sid, EvaluableNodeImmediateValueType value_type, EvaluableNodeImmediateValue &value, BitArrayIntegerSet &out) { - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) return; size_t column_index = column->second; @@ -400,11 +400,11 @@ class SeparableBoxFilterDataStore } //Finds the Minimum or Maximum (with respect to feature_id feature value) num_to_find entities in the database; if is_max is true, finds max, else finds min - inline void FindMinMax(size_t feature_id, + inline void FindMinMax(StringInternPool::StringID feature_sid, EvaluableNodeImmediateValueType value_type, size_t num_to_find, bool is_max, BitArrayIntegerSet *enabled_indices, BitArrayIntegerSet &out) { - auto column = labelIdToColumnIndex.find(feature_id); + auto column = labelIdToColumnIndex.find(feature_sid); if(column == labelIdToColumnIndex.end()) return; @@ -485,7 +485,7 @@ class SeparableBoxFilterDataStore //populates distances_out with all entities and their distances that have a distance to target less than max_dist //if enabled_indices is not nullptr, intersects with the enabled_indices set. //assumes that enabled_indices only contains indices that have valid values for all the features - void FindEntitiesWithinDistance(GeneralizedDistanceEvaluator &r_dist_eval, std::vector &position_label_ids, + void FindEntitiesWithinDistance(GeneralizedDistanceEvaluator &r_dist_eval, std::vector &position_label_sids, std::vector &position_values, std::vector &position_value_types, double max_dist, StringInternPool::StringID radius_label, BitArrayIntegerSet &enabled_indices, std::vector> &distances_out); @@ -494,7 +494,7 @@ class SeparableBoxFilterDataStore // if expand_to_first_nonzero_distance is set, then it will expand top_k until it it finds the first nonzero distance or until it includes all enabled indices //will not modify enabled_indices, but instead will make a copy for any modifications //assumes that enabled_indices only contains indices that have valid values for all the features - void FindEntitiesNearestToIndexedEntity(GeneralizedDistanceEvaluator &dist_eval, std::vector &position_label_ids, + void FindEntitiesNearestToIndexedEntity(GeneralizedDistanceEvaluator &dist_eval, std::vector &position_label_sids, size_t search_index, size_t top_k, StringInternPool::StringID radius_label, BitArrayIntegerSet &enabled_indices, bool expand_to_first_nonzero_distance, std::vector> &distances_out, @@ -503,7 +503,7 @@ class SeparableBoxFilterDataStore //Finds the nearest neighbors //enabled_indices is the set of entities to find from, and will be modified //assumes that enabled_indices only contains indices that have valid values for all the features - void FindNearestEntities(GeneralizedDistanceEvaluator &dist_eval, std::vector &position_label_ids, + void FindNearestEntities(GeneralizedDistanceEvaluator &dist_eval, std::vector &position_label_sids, std::vector &position_values, std::vector &position_value_types, size_t top_k, StringInternPool::StringID radius_label, size_t ignore_entity_index, BitArrayIntegerSet &enabled_indices, std::vector> &distances_out, RandomStream rand_stream = RandomStream()); @@ -539,7 +539,7 @@ class SeparableBoxFilterDataStore //adds a new labels to the database // assumes label_ids is not empty and num_entities is nonzero //returns the number of new columns inserted - size_t AddLabelsAsEmptyColumns(std::vector &label_ids, size_t num_entities); + size_t AddLabelsAsEmptyColumns(std::vector &label_sids, size_t num_entities); //computes each partial sum and adds the term to the partial sums associated for each id in entity_indices for query_feature_index //returns the number of entities indices accumulated @@ -946,14 +946,14 @@ class SeparableBoxFilterDataStore //populates all target values given the selected target values for each value in corresponding position* parameters void PopulateTargetValuesAndLabelIndices(RepeatedGeneralizedDistanceEvaluator &r_dist_eval, - std::vector &position_label_ids, std::vector &position_values, + std::vector &position_label_sids, std::vector &position_values, std::vector &position_value_types) { size_t num_features = position_values.size(); r_dist_eval.featureData.resize(num_features); for(size_t query_feature_index = 0; query_feature_index < num_features; query_feature_index++) { - auto column = labelIdToColumnIndex.find(position_label_ids[query_feature_index]); + auto column = labelIdToColumnIndex.find(position_label_sids[query_feature_index]); if(column != end(labelIdToColumnIndex)) PopulateTargetValueAndLabelIndex(r_dist_eval, query_feature_index, position_values[query_feature_index], position_value_types[query_feature_index]); @@ -962,11 +962,11 @@ class SeparableBoxFilterDataStore //sets values in dist_eval corresponding to the columns specified by position_label_ids inline void PopulateGeneralizedDistanceEvaluatorFromColumnData( - GeneralizedDistanceEvaluator &dist_eval, std::vector &position_label_ids) + GeneralizedDistanceEvaluator &dist_eval, std::vector &position_label_sids) { - for(size_t query_feature_index = 0; query_feature_index < position_label_ids.size(); query_feature_index++) + for(size_t query_feature_index = 0; query_feature_index < position_label_sids.size(); query_feature_index++) { - auto column = labelIdToColumnIndex.find(position_label_ids[query_feature_index]); + auto column = labelIdToColumnIndex.find(position_label_sids[query_feature_index]); if(column == end(labelIdToColumnIndex)) continue; diff --git a/src/Amalgam/entity/Entity.cpp b/src/Amalgam/entity/Entity.cpp index ddd43411..8216a26b 100644 --- a/src/Amalgam/entity/Entity.cpp +++ b/src/Amalgam/entity/Entity.cpp @@ -122,7 +122,7 @@ Entity::~Entity() EvaluableNodeReference Entity::GetValueAtLabel(StringInternPool::StringID label_sid, EvaluableNodeManager *destination_temp_enm, bool direct_get, bool on_self, bool batch_call) { - if(label_sid <= StringInternPool::EMPTY_STRING_ID) + if(label_sid == string_intern_pool.NOT_A_STRING_ID) return EvaluableNodeReference::Null(); if(!on_self && IsLabelPrivate(label_sid)) @@ -149,7 +149,7 @@ bool Entity::GetValueAtLabelAsNumber(StringInternPool::StringID label_sid, doubl { constexpr double value_if_not_found = std::numeric_limits::quiet_NaN(); - if(label_sid <= StringInternPool::EMPTY_STRING_ID) + if(label_sid == string_intern_pool.NOT_A_STRING_ID) { value_out = value_if_not_found; return false; @@ -174,7 +174,7 @@ bool Entity::GetValueAtLabelAsNumber(StringInternPool::StringID label_sid, doubl bool Entity::GetValueAtLabelAsStringId(StringInternPool::StringID label_sid, StringInternPool::StringID &value_out, bool on_self) { - if(label_sid <= StringInternPool::EMPTY_STRING_ID) + if(label_sid == string_intern_pool.NOT_A_STRING_ID) { value_out = StringInternPool::NOT_A_STRING_ID; return false; @@ -199,7 +199,7 @@ bool Entity::GetValueAtLabelAsStringId(StringInternPool::StringID label_sid, Str bool Entity::GetValueAtLabelAsString(StringInternPool::StringID label_sid, std::string &value_out, bool on_self) { - if(label_sid <= StringInternPool::EMPTY_STRING_ID) + if(label_sid == string_intern_pool.NOT_A_STRING_ID) { value_out = ""; return false; @@ -244,7 +244,7 @@ EvaluableNodeImmediateValueType Entity::GetValueAtLabelAsImmediateValue(StringIn bool Entity::SetValueAtLabel(StringInternPool::StringID label_sid, EvaluableNodeReference &new_value, bool direct_set, std::vector *write_listeners, bool on_self, bool batch_call, bool *need_node_flags_updated) { - if(label_sid <= StringInternPool::EMPTY_STRING_ID) + if(label_sid == string_intern_pool.NOT_A_STRING_ID) return false; if(!on_self) @@ -459,7 +459,7 @@ EvaluableNodeReference Entity::Execute(StringInternPool::StringID label_sid, return EvaluableNodeReference(nullptr, true); EvaluableNode *node_to_execute = nullptr; - if(label_sid <= StringInternPool::EMPTY_STRING_ID) //if not specified, then use root + if(label_sid == string_intern_pool.NOT_A_STRING_ID) //if not specified, then use root node_to_execute = evaluableNodeManager.GetRootNode(); else //get code at label { diff --git a/src/Amalgam/entity/EntityQueries.h b/src/Amalgam/entity/EntityQueries.h index 495bd797..e3002c1d 100644 --- a/src/Amalgam/entity/EntityQueries.h +++ b/src/Amalgam/entity/EntityQueries.h @@ -69,6 +69,9 @@ class EntityQueryCondition //a label of an id to exclude StringInternPool::StringID exclusionLabel; + //index of an entity to exclude + size_t exclusionEntityIndex; + //a label representing a weight label StringInternPool::StringID weightLabel; diff --git a/src/Amalgam/entity/EntityQueryCaches.cpp b/src/Amalgam/entity/EntityQueryCaches.cpp index 000f4362..5b6339ea 100644 --- a/src/Amalgam/entity/EntityQueryCaches.cpp +++ b/src/Amalgam/entity/EntityQueryCaches.cpp @@ -318,7 +318,7 @@ void EntityQueryCaches::GetMatchingEntities(EntityQueryCondition *cond, BitArray else if(cond->queryType == ENT_QUERY_NEAREST_GENERALIZED_DISTANCE) { sbfds.FindNearestEntities(cond->distEvaluator, cond->positionLabels, cond->valueToCompare, cond->valueTypes, - static_cast(cond->maxToRetrieve), cond->singleLabel, cond->exclusionLabel, matching_entities, + static_cast(cond->maxToRetrieve), cond->singleLabel, cond->exclusionEntityIndex, matching_entities, compute_results, cond->randomStream.CreateOtherStreamViaRand()); } else //ENT_QUERY_WITHIN_GENERALIZED_DISTANCE @@ -901,7 +901,7 @@ void EntityQueryCaches::GetMatchingEntitiesViaSamplingWithReplacement(EntityQuer else //sampling a bunch, better to precompute and use faster method { //a table for quickly generating entity indices based on weights - WeightedDiscreteRandomStreamTransform> ewt(entity_indices, probabilities, false); + WeightedDiscreteRandomStreamTransform> ewt(entity_indices, probabilities, false); //sample the entities for(size_t i = 0; i < num_to_sample; i++) @@ -1006,9 +1006,9 @@ EvaluableNodeReference EntityQueryCaches::GetMatchingEntitiesFromQueryCaches(Ent { //if excluding an entity, translate it into the index if(cond.exclusionLabel == string_intern_pool.NOT_A_STRING_ID) - cond.exclusionLabel = std::numeric_limits::max(); + cond.exclusionEntityIndex = std::numeric_limits::max(); else - cond.exclusionLabel = container->GetContainedEntityIndex(cond.exclusionLabel); + cond.exclusionEntityIndex = container->GetContainedEntityIndex(cond.exclusionLabel); //fall through to cases below } diff --git a/src/Amalgam/evaluablenode/EvaluableNode.h b/src/Amalgam/evaluablenode/EvaluableNode.h index 1bc1bc17..495c2f97 100644 --- a/src/Amalgam/evaluablenode/EvaluableNode.h +++ b/src/Amalgam/evaluablenode/EvaluableNode.h @@ -808,7 +808,7 @@ class EvaluableNode protected: - //align to the nearest 2-bytes to minimize aligment issues but reduce the overall memory footprint + //align to the nearest 2-bytes to minimize alignment issues but reduce the overall memory footprint // while maintaining some alignment #pragma pack(push, 2) union EvaluableNodeValue diff --git a/src/Amalgam/evaluablenode/EvaluableNodeManagement.h b/src/Amalgam/evaluablenode/EvaluableNodeManagement.h index 0139af2c..316ed1e4 100644 --- a/src/Amalgam/evaluablenode/EvaluableNodeManagement.h +++ b/src/Amalgam/evaluablenode/EvaluableNodeManagement.h @@ -20,7 +20,7 @@ class EvaluableNodeReference { public: constexpr EvaluableNodeReference() - : value(nullptr), unique(true) + : value(), unique(true) { } constexpr EvaluableNodeReference(EvaluableNode *_reference, bool _unique) @@ -102,7 +102,7 @@ class EvaluableNodeReference } //calls GetNeedCycleCheck if the reference is not nullptr, returns false if it is nullptr - constexpr bool GetNeedCycleCheck() + __forceinline bool GetNeedCycleCheck() { if(value.nodeType != ENIVT_CODE) return false; @@ -114,7 +114,7 @@ class EvaluableNodeReference } //calls SetNeedCycleCheck if the reference is not nullptr - constexpr void SetNeedCycleCheck(bool need_cycle_check) + __forceinline void SetNeedCycleCheck(bool need_cycle_check) { if(value.nodeValue.code == nullptr) return; @@ -123,7 +123,7 @@ class EvaluableNodeReference } //returns true if the reference is idempotent - constexpr bool GetIsIdempotent() + __forceinline bool GetIsIdempotent() { if(value.nodeType != ENIVT_CODE) return true; @@ -135,7 +135,7 @@ class EvaluableNodeReference } //sets idempotency if the reference is code and not nullptr - constexpr void SetIsIdempotent(bool is_idempotent) + __forceinline void SetIsIdempotent(bool is_idempotent) { if(value.nodeType != ENIVT_CODE) return; @@ -146,7 +146,7 @@ class EvaluableNodeReference return value.nodeValue.code->SetIsIdempotent(is_idempotent); } - constexpr static EvaluableNodeReference Null() + __forceinline static EvaluableNodeReference Null() { return EvaluableNodeReference(nullptr, true); } diff --git a/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp b/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp index 9720a4c1..8083c868 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesBase.cpp @@ -587,7 +587,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_WHILE(EvaluableNode *en, b SetTopPreviousResultInConstructionStack(previous_result); //run each step within the loop - EvaluableNodeReference new_result; + EvaluableNodeReference new_result = EvaluableNodeReference::Null(); for(size_t i = 1; i < ocn_size; i++) { //request immediate values when not last, since any allocs for returns would be wasted @@ -899,8 +899,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_ASSIGN_and_ACCUM(Evaluable if(accum) { //retrieve value_destination_node - EvaluableNodeReference value_destination_node; - value_destination_node.SetReference(*value_destination, false); + EvaluableNodeReference value_destination_node(*value_destination, false); #ifdef MULTITHREAD_SUPPORT //if editing a shared variable, then need to make a copy before editing in place to prevent another thread from reading the data structure mid-edit @@ -951,8 +950,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_ASSIGN_and_ACCUM(Evaluable if(accum) { //create destination reference - EvaluableNodeReference value_destination_node; - value_destination_node.SetReference(*value_destination, false); + EvaluableNodeReference value_destination_node(*value_destination, false); #ifdef MULTITHREAD_SUPPORT //if editing a shared variable, then need to make a copy before editing in place to prevent another thread from reading the data structure mid-edit @@ -1034,8 +1032,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_ASSIGN_and_ACCUM(Evaluable if(accum) { //create destination reference - EvaluableNodeReference value_destination_node; - value_destination_node.SetReference(*copy_destination, false); + EvaluableNodeReference value_destination_node(*copy_destination, false); EvaluableNodeReference variable_value_node = AccumulateEvaluableNodeIntoEvaluableNode(value_destination_node, new_value, evaluableNodeManager); @@ -1904,7 +1901,8 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_WEIGHTED_RAND(EvaluableNod //if generating many values with weighted probabilites, use fast method if(mcn.size() > 0 && (number_to_generate > 10 || (number_to_generate > 3 && mcn.size() > 200))) { - EvaluableNodeMappedWeightedDiscreteRandomStreamTransform wdrst(mcn, false); + WeightedDiscreteRandomStreamTransform wdrst(mcn, false); for(size_t i = 0; i < number_to_generate; i++) { EvaluableNode *rand_value = evaluableNodeManager->AllocNode(ENT_STRING, wdrst.WeightedDiscreteRand(randomStream)); diff --git a/src/Amalgam/interpreter/InterpreterOpcodesDataTypes.cpp b/src/Amalgam/interpreter/InterpreterOpcodesDataTypes.cpp index b9ee0443..10eb4567 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesDataTypes.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesDataTypes.cpp @@ -298,7 +298,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_FORMAT(EvaluableNode *en, auto node_stack = CreateInterpreterNodeStackStateSaver(); bool node_stack_needs_popping = false; - EvaluableNodeReference from_params; + EvaluableNodeReference from_params = EvaluableNodeReference::Null(); if(ocn.size() > 3) { from_params = InterpretNodeForImmediateUse(ocn[3]); @@ -307,7 +307,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_FORMAT(EvaluableNode *en, } bool use_code = false; - EvaluableNodeReference code_value; + EvaluableNodeReference code_value = EvaluableNodeReference::Null(); bool use_number = false; double number_value = 0; @@ -551,7 +551,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_FORMAT(EvaluableNode *en, node_stack.PopEvaluableNode(); evaluableNodeManager->FreeNodeTreeIfPossible(from_params); - EvaluableNodeReference to_params; + EvaluableNodeReference to_params = EvaluableNodeReference::Null(); if(ocn.size() > 4) to_params = InterpretNodeForImmediateUse(ocn[4]); @@ -1518,7 +1518,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_SUBSTR(EvaluableNode *en, } else //finding matches { - EvaluableNodeReference param_node; + EvaluableNodeReference param_node = EvaluableNodeReference::Null(); if(ocn.size() >= 3) param_node = InterpretNodeForImmediateUse(ocn[2]); diff --git a/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp b/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp index 467f7f9e..f9b38f43 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesEntityAccess.cpp @@ -46,8 +46,8 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_CONTAINED_ENTITIES_and_COM bool return_query_value = (en->GetType() == ENT_COMPUTE_ON_CONTAINED_ENTITIES); //parameters to search entities for - EvaluableNodeReference query_params; - EvaluableNodeReference entity_id_path; + EvaluableNodeReference query_params = EvaluableNodeReference::Null(); + EvaluableNodeReference entity_id_path = EvaluableNodeReference::Null(); auto &ocn = en->GetOrderedChildNodes(); if(ocn.size() == 1) diff --git a/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp b/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp index 4d16d2a0..4fc3121d 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesMath.cpp @@ -343,7 +343,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_SET_DIGITS(EvaluableNode * if(num_params > 4) end_digit = InterpretNodeIntoNumberValue(ocn[4]); - EvaluableNodeReference digits; + EvaluableNodeReference digits = EvaluableNodeReference::Null(); if(num_params > 2) digits = InterpretNodeForImmediateUse(ocn[2]); @@ -458,7 +458,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_ROUND(EvaluableNode *en, b if(num_params == 0) return EvaluableNodeReference::Null(); - EvaluableNodeReference retval; + EvaluableNodeReference retval = EvaluableNodeReference::Null(); double number_value = 0.0; if(immediate_result) diff --git a/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp b/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp index 37be2926..194f3c51 100644 --- a/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp +++ b/src/Amalgam/interpreter/InterpreterOpcodesTransformations.cpp @@ -863,7 +863,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_SORT(EvaluableNode *en, bo size_t list_index = (ocn.size() == 1 ? 0 : 1); - EvaluableNodeReference function; + EvaluableNodeReference function = EvaluableNodeReference::Null(); size_t highest_k = 0; size_t lowest_k = 0; @@ -1545,7 +1545,7 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_ASSOCIATE(EvaluableNode *e SetTopCurrentIndexInConstructionStack(key_sid); //compute the value, but make sure have another node - EvaluableNodeReference value; + EvaluableNodeReference value = EvaluableNodeReference::Null(); if(i + 1 < num_nodes) value = InterpretNode(ocn[i + 1]);