OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/geolocation/wifi_data.h" | 5 #include "device/geolocation/wifi_data.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 WifiData::~WifiData() {} | 28 WifiData::~WifiData() {} |
29 | 29 |
30 bool WifiData::DiffersSignificantly(const WifiData& other) const { | 30 bool WifiData::DiffersSignificantly(const WifiData& other) const { |
31 // More than 4 or 50% of access points added or removed is significant. | 31 // More than 4 or 50% of access points added or removed is significant. |
32 static const size_t kMinChangedAccessPoints = 4; | 32 static const size_t kMinChangedAccessPoints = 4; |
33 const size_t min_ap_count = | 33 const size_t min_ap_count = |
34 std::min(access_point_data.size(), other.access_point_data.size()); | 34 std::min(access_point_data.size(), other.access_point_data.size()); |
35 const size_t max_ap_count = | 35 const size_t max_ap_count = |
36 std::max(access_point_data.size(), other.access_point_data.size()); | 36 std::max(access_point_data.size(), other.access_point_data.size()); |
37 const size_t difference_threadhold = std::min(kMinChangedAccessPoints, | 37 const size_t difference_threadhold = |
38 min_ap_count / 2); | 38 std::min(kMinChangedAccessPoints, min_ap_count / 2); |
39 if (max_ap_count > min_ap_count + difference_threadhold) | 39 if (max_ap_count > min_ap_count + difference_threadhold) |
40 return true; | 40 return true; |
41 // Compute size of intersection of old and new sets. | 41 // Compute size of intersection of old and new sets. |
42 size_t num_common = 0; | 42 size_t num_common = 0; |
43 for (AccessPointDataSet::const_iterator iter = access_point_data.begin(); | 43 for (AccessPointDataSet::const_iterator iter = access_point_data.begin(); |
44 iter != access_point_data.end(); | 44 iter != access_point_data.end(); iter++) { |
45 iter++) { | 45 if (other.access_point_data.find(*iter) != other.access_point_data.end()) { |
46 if (other.access_point_data.find(*iter) != | |
47 other.access_point_data.end()) { | |
48 ++num_common; | 46 ++num_common; |
49 } | 47 } |
50 } | 48 } |
51 DCHECK(num_common <= min_ap_count); | 49 DCHECK(num_common <= min_ap_count); |
52 | 50 |
53 // Test how many have changed. | 51 // Test how many have changed. |
54 return max_ap_count > num_common + difference_threadhold; | 52 return max_ap_count > num_common + difference_threadhold; |
55 } | 53 } |
56 | 54 |
57 } // namespace device | 55 } // namespace device |
OLD | NEW |