| 220 | { |
| 221 | template <typename T, typename U> |
| 222 | typename T::value_type::second_type general_dot ( |
| 223 | const T& a, |
| 224 | const U& b |
| 225 | ) |
| 226 | { |
| 227 | typedef typename T::value_type::second_type scalar_type; |
| 228 | |
| 229 | typename T::const_iterator ai = a.begin(); |
| 230 | typename U::const_iterator bi = b.begin(); |
| 231 | |
| 232 | scalar_type sum = 0; |
| 233 | while (ai != a.end() && bi != b.end()) |
| 234 | { |
| 235 | if (ai->first == bi->first) |
| 236 | { |
| 237 | sum += ai->second * bi->second; |
| 238 | ++ai; |
| 239 | ++bi; |
| 240 | } |
| 241 | else if (ai->first < bi->first) |
| 242 | { |
| 243 | ++ai; |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | ++bi; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | return sum; |
| 252 | } |
| 253 | |
| 254 | template <typename T, typename U> |
| 255 | inline typename T::value_type::second_type dot ( |