Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
实时编辑器
隐藏空白更改
折叠未更改行
关闭换行
视图
拆分
统一
比对精度
智能
单词
字符
文本样式
更改外观
语法高亮
选择语法
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
https://codereview.stackexchange.com/a/253314/30419
创建于
6年前
差异永不过期
清除
导出
分享
解释
55 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
55 行
全部复制
52 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
55 行
全部复制
复制
已复制
复制
已复制
#define
queueSize
16
let
queueSize
=
16
复制
已复制
复制
已复制
#define
increaseIndex(
x) ({x++; if(x >= queueSize) x = 0;})
func
increaseIndex(
_ x: Int) -> Int {
let x = x + 1
return x < queueSize
? x
: 0
}
复制
已复制
复制
已复制
int
rssiArray
[queueSize]
=
{0};
var
rssiArray
=
[0]
int
sortRssi
[queueSize]
=
{0};
var
sortRssi
=
[0]
int
rssiIndex = 0
;
var
rssiIndex = 0
复制
已复制
复制
已复制
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));
}
}
复制
已复制
复制
已复制
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;
}
}
复制
已复制
复制
已复制
let ratio = rssi * (1 / Double(txPower))
return ratio < 1
? pow(ratio, 10)
: (0.89976) * pow(ratio, 7.7095) + 0.111
}
}
复制
已复制
复制
已复制
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 })
}
}
复制
已复制
复制
已复制
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];
}
}
复制
已复制
复制
已复制
return average / i;
}
}
// For adding new rssi we can use this code:
// For adding new rssi we can use this code:
复制
已复制
复制
已复制
rssiArray[rssiIndex] = rssi
;
rssiArray[rssiIndex] = rssi
increaseIndex(rssiIndex)
;
rssiIndex =
increaseIndex(rssiIndex)
double
meanRssi = calculateAverage()
;
let
meanRssi = calculateAverage()
已保存差异
原始文本
打开文件
#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();
更改后文本
打开文件
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()
查找差异