comparison libinterp/octave-value/ov-struct.h @ 31260:c5c8bf50449c

Improve performance of isfield from linear time to constant time (bug #58105) Patch author: Anonymous in Bug #58105 Comment #7 https://savannah.gnu.org/bugs/index.php?58105#comment7 The isfield function was taking time proportional to the number of fields in a struct to determine whether something was a member or not. With this change, isfield performance becomes constant irrespective of the number of fields, speeding up performance by over 200X, and also allowing the use of struct as a hashmap if the user desires. ov-base.h: Add new isfield function declaration ov-base.cc: Add new isfield function definition ov-struct.h: Add new isfield function definitions ov-struct.cc: Do not call map_value ov.h: Add new isfield function definition
author Arun Giridhar <arungiridhar@gmail.com>
date Wed, 05 Oct 2022 10:35:31 -0400
parents 796f54d4ddbf
children 597f3ee61a48
comparison
equal deleted inserted replaced
31259:e39634a768e7 31260:c5c8bf50449c
128 128
129 octave_map map_value (void) const { return m_map; } 129 octave_map map_value (void) const { return m_map; }
130 130
131 string_vector map_keys (void) const { return m_map.fieldnames (); } 131 string_vector map_keys (void) const { return m_map.fieldnames (); }
132 132
133 bool isfield (const std::string& field_name) const
134 { return m_map.isfield (field_name); }
135
133 void print (std::ostream& os, bool pr_as_read_syntax = false); 136 void print (std::ostream& os, bool pr_as_read_syntax = false);
134 137
135 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; 138 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
136 139
137 bool print_name_tag (std::ostream& os, const std::string& name) const; 140 bool print_name_tag (std::ostream& os, const std::string& name) const;
254 257
255 octave_scalar_map scalar_map_value (void) const { return m_map; } 258 octave_scalar_map scalar_map_value (void) const { return m_map; }
256 259
257 string_vector map_keys (void) const { return m_map.fieldnames (); } 260 string_vector map_keys (void) const { return m_map.fieldnames (); }
258 261
262 bool isfield (const std::string& field_name) const
263 { return m_map.isfield (field_name); }
264
259 void print (std::ostream& os, bool pr_as_read_syntax = false); 265 void print (std::ostream& os, bool pr_as_read_syntax = false);
260 266
261 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; 267 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
262 268
263 bool print_name_tag (std::ostream& os, const std::string& name) const; 269 bool print_name_tag (std::ostream& os, const std::string& name) const;