Diff
checker
Text
Text
Images
Documents
Excel
Folders
Legal
Enterprise
Desktop
Pricing
Sign in
Download Diffchecker Desktop
Compare text
Find the difference between two text files
Tools
History
Real-time editor
Hide whitespace changes
Hide unchanged lines
Disable line wrap
Layout
Split
Unified
Diff precision
Smart
Word
Char
Text styles
Change appearance
Syntax highlighting
Choose syntax
Ignore
Transform text
Go to first change
Edit input
Diffchecker Desktop
The most secure way to run Diffchecker. Get the Diffchecker Desktop app: your diffs never leave your computer!
Get Desktop
https://codereview.stackexchange.com/a/253314/30419
Created
6 years ago
Diff never expires
Clear
Export
Share
Explain
55 removals
Lines
Total
Removed
Characters
Total
Removed
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
55 lines
Copy
52 additions
Lines
Total
Added
Characters
Total
Added
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
55 lines
Copy
Copy
Copied
Copy
Copied
#define
queueSize
16
let
queueSize
=
16
Copy
Copied
Copy
Copied
#define
increaseIndex(
x) ({x++; if(x >= queueSize) x = 0;})
func
increaseIndex(
_ x: Int) -> Int {
let x = x + 1
return x < queueSize
? x
: 0
}
Copy
Copied
Copy
Copied
int
rssiArray
[queueSize]
=
{0};
var
rssiArray
=
[0]
int
sortRssi
[queueSize]
=
{0};
var
sortRssi
=
[0]
int
rssiIndex = 0
;
var
rssiIndex = 0
Copy
Copied
Copy
Copied
static double
getDistance(
d
ouble
rssi, int
txPower
)
{
private func
getDistance(
rssi: D
ouble
,
txPower
: Int) -> Double?
{
if (
rssi == 0
) {
return
rssi == 0
return -1.0; // if we cannot determine accuracy, return -1.
? nil
}
:
pow(10, (
D
ouble
(
txPower
)
- rssi) /
20)
return
pow(10, (
(d
ouble
)
txPower
- rssi) /
(10 * 2));
}
}
Copy
Copied
Copy
Copied
static double calculateAccuracy(double rssi, int txPower) {
private func calculateAccuracy(rssi: Double, txPower: Int) -> Double? {
if (rssi == 0) {
guard rssi != 0 else {
return -1.0; // if we cannot determine accuracy, return -1.
return
nil
}
double ratio = rssi * 1.0 / txPower;
if (ratio < 1.0) {
return
pow(ratio, 10);
} else {
double accuracy = (0.89976) * pow(ratio, 7.7095) + 0.111;
return accuracy;
}
}
Copy
Copied
Copy
Copied
let ratio = rssi * (1 / Double(txPower))
return ratio < 1
? pow(ratio, 10)
: (0.89976) * pow(ratio, 7.7095) + 0.111
}
}
Copy
Copied
Copy
Copied
int cmp
func
(const void * a, const void * b)
{
private
func
calculateAverage() -> Double
{
return
( *(int*)a - *(int*)b );
sortRssi = Array(rssiArray.sorted(by: >).dropFirst(3))
return
sortRssi.averaged(while: { $0 != 0 })
}
}
Copy
Copied
Copy
Copied
static double calculateAverage()
{
double
average
= 0;
extension Collection where Element: BinaryInteger
{
int i = 0;
func
average
d(while allowedPrefixPredicate: (Element) -> Bool) -> Double {
int drop = 3;
lazy
memcpy(sort_rssi, rssi_array, queueSize * sizeof(int));
.prefix(while: allowedPrefixPredicate)
qsort(sort_rssi, queueSize, sizeof(int), cmpfunc);
.map(Double.init)
for (i = 0; i < queueSize - drop; ++i) {
.reduce(into: 0, +=)
if(sort_rssi[i + drop] == 0) break;
/ Double(count)
average += sort_rssi[i];
}
}
Copy
Copied
Copy
Copied
return average / i;
}
}
// For adding new rssi we can use this code:
// For adding new rssi we can use this code:
Copy
Copied
Copy
Copied
rssiArray[rssiIndex] = rssi
;
rssiArray[rssiIndex] = rssi
increaseIndex(rssiIndex)
;
rssiIndex =
increaseIndex(rssiIndex)
double
meanRssi = calculateAverage()
;
let
meanRssi = calculateAverage()
Saved diffs
Original text
Open file
#define queueSize 16 #define increaseIndex(x) ({x++; if(x >= queueSize) x = 0;}) int rssiArray[queueSize] = {0}; int sortRssi[queueSize] = {0}; int rssiIndex = 0; static double getDistance(double rssi, int txPower) { if (rssi == 0) { return -1.0; // if we cannot determine accuracy, return -1. } return pow(10, ((double) txPower - rssi) / (10 * 2)); } static double calculateAccuracy(double rssi, int txPower) { if (rssi == 0) { return -1.0; // if we cannot determine accuracy, return -1. } double ratio = rssi * 1.0 / txPower; if (ratio < 1.0) { return pow(ratio, 10); } else { double accuracy = (0.89976) * pow(ratio, 7.7095) + 0.111; return accuracy; } } int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } static double calculateAverage() { double average = 0; int i = 0; int drop = 3; memcpy(sort_rssi, rssi_array, queueSize * sizeof(int)); qsort(sort_rssi, queueSize, sizeof(int), cmpfunc); for (i = 0; i < queueSize - drop; ++i) { if(sort_rssi[i + drop] == 0) break; average += sort_rssi[i]; } return average / i; } // For adding new rssi we can use this code: rssiArray[rssiIndex] = rssi; increaseIndex(rssiIndex); double meanRssi = calculateAverage();
Changed text
Open file
let queueSize = 16 func increaseIndex(_ x: Int) -> Int { let x = x + 1 return x < queueSize ? x : 0 } var rssiArray = [0] var sortRssi = [0] var rssiIndex = 0 private func getDistance(rssi: Double, txPower: Int) -> Double? { return rssi == 0 ? nil : pow(10, (Double(txPower) - rssi) / 20) } private func calculateAccuracy(rssi: Double, txPower: Int) -> Double? { guard rssi != 0 else { return nil } let ratio = rssi * (1 / Double(txPower)) return ratio < 1 ? pow(ratio, 10) : (0.89976) * pow(ratio, 7.7095) + 0.111 } private func calculateAverage() -> Double { sortRssi = Array(rssiArray.sorted(by: >).dropFirst(3)) return sortRssi.averaged(while: { $0 != 0 }) } extension Collection where Element: BinaryInteger { func averaged(while allowedPrefixPredicate: (Element) -> Bool) -> Double { lazy .prefix(while: allowedPrefixPredicate) .map(Double.init) .reduce(into: 0, +=) / Double(count) } } // For adding new rssi we can use this code: rssiArray[rssiIndex] = rssi rssiIndex = increaseIndex(rssiIndex) let meanRssi = calculateAverage()
Find difference