Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
텍스트 스타일
모양 변경
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 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()
비교하기