GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Replacing std::map::operator[] with std::map::at or std::map::insert · walshjon/pyne@970f33b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • data.cpp
    • material.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/data.cpp‎

Copy file name to clipboardExpand all lines: src/data.cpp
+14-11Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ void pyne::_load_atomic_mass_map() {
7373
H5Dclose(atomic_mass_set);
7474
H5Fclose(nuc_data_h5);
7575

76-
// Ok now that we have the array of stucts, put it in the map
76+
// Ok now that we have the array of structs, put it in the map
7777
for(int n = 0; n < atomic_mass_length; n++) {
78-
atomic_mass_map[atomic_mass_array[n].nuc] = atomic_mass_array[n].mass;
79-
natural_abund_map[atomic_mass_array[n].nuc] = atomic_mass_array[n].abund;
78+
atomic_mass_map.insert(std::pair<int, double>(atomic_mass_array[n].nuc, \
79+
atomic_mass_array[n].mass));
80+
natural_abund_map.insert(std::pair<int, double>(atomic_mass_array[n].nuc, \
81+
atomic_mass_array[n].abund));
8082
}
8183

8284
delete[] atomic_mass_array;
@@ -91,12 +93,8 @@ double pyne::atomic_mass(int nuc) {
9193
nuc_end = atomic_mass_map.end();
9294

9395
// First check if we already have the nuc mass in the map
94-
double aw;
9596
if (nuc_iter != nuc_end) {
96-
aw = nuc_iter->second;
97-
if (aw != 0.0) {
98-
return (*nuc_iter).second;
99-
}
97+
return (*nuc_iter).second;
10098
}
10199

102100
// Next, fill up the map with values from the
@@ -107,21 +105,26 @@ double pyne::atomic_mass(int nuc) {
107105
return atomic_mass(nuc);
108106
}
109107

108+
double aw;
110109
int nucid = nucname::id(nuc);
111110

112111
// If in an excited state, return the ground
113112
// state mass...not strictly true, but good guess.
114113
if (0 < nucid%10000) {
115114
aw = atomic_mass((nucid/10000)*10000);
116-
atomic_mass_map[nuc] = aw;
115+
if (atomic_mass_map.count(nuc) != 1) {
116+
atomic_mass_map.insert(std::pair<int, double>(nuc, aw));
117+
}
117118
return aw;
118119
};
119120

120121
// Finally, if none of these work,
121122
// take a best guess based on the
122123
// aaa number.
123124
aw = (double) ((nucid/10000)%1000);
124-
atomic_mass_map[nuc] = aw;
125+
if (atomic_mass_map.count(nuc) != 1) {
126+
atomic_mass_map.insert(std::pair<int, double>(nuc, aw));
127+
}
125128
return aw;
126129
};
127130

@@ -170,7 +173,7 @@ double pyne::natural_abund(int nuc) {
170173
// state abundance...not strictly true, but good guess.
171174
if (0 < nucid%10000) {
172175
na = natural_abund((nucid/10000)*10000);
173-
atomic_mass_map[nuc] = na;
176+
natural_abund_map[nuc] = na;
174177
return na;
175178
};
176179

Collapse file

‎src/material.cpp‎

Copy file name to clipboardExpand all lines: src/material.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ pyne::Material pyne::Material::expand_elements() {
11511151
nabund = (*abund_itr).first;
11521152
if (zabund == znuc && 0 != nucname::anum(nabund) && 0.0 != (*abund_itr).second)
11531153
newcomp[nabund] = (*abund_itr).second * (*nuc).second * \
1154-
atomic_mass_map[nabund] / atomic_mass_map[n];
1154+
atomic_mass_map.at(nabund) / atomic_mass_map.at(n);
11551155
else if (n == nabund && 0.0 == (*abund_itr).second)
11561156
newcomp.insert(*nuc);
11571157
abund_itr++;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.