fixed character count

This commit is contained in:
Haik Aslanyan committed 2020-04-12 19:41:28 +04:00
1 parent 55684f28a4
commit b08a752369
2 files changed
+4 -4

No files matched your search

+3 -3
View File
@@ -49,9 +49,9 @@ extension RCBitCoder {
//adding staring character index and filling with special indexes
indexes.insert(configuration.characters.firstIndex(of: configuration.version.startingCharacter)!, at: 0)
let emptyIndexes = configuration.version.emptyCharacters.map({configuration.characters.firstIndex(of: $0)!})
let randomBytes = (0..<configuration.maxMessageCount).map({_ in emptyIndexes[Int.random(in: 0..<emptyIndexes.count)]})
let randomBytes = (0...configuration.maxMessageCount).map({_ in emptyIndexes[Int.random(in: 0..<emptyIndexes.count)]})
indexes.append(contentsOf: randomBytes)
indexes = Array(indexes.prefix(configuration.maxMessageCount))
indexes = Array(indexes.prefix(configuration.maxMessageCount + 1))
//encoding into bits
let encodedBits = indexes.map { byte -> [RCBit] in
var stringValue = String(repeating: "0", count: configuration.bitesPerSymbol)
@@ -96,7 +96,7 @@ extension RCBitCoder {
//mapping to custom size byte
let bytes = stride(from: 0, to: dataBits.count, by: configuration.bitesPerSymbol).map {
Array(dataBits[$0 ..< min($0 + configuration.bitesPerSymbol, dataBits.count)])
}.prefix(configuration.maxMessageCount)
}.prefix(configuration.maxMessageCount + 1)
//converting binary into decimal
let indexes = bytes.map({ bits in
return bits.reduce(0) { accumulated, current in
+1 -1
View File
@@ -36,7 +36,7 @@ public struct RCCoderConfiguration {
charactersArray.append(contentsOf: version.emptyCharacters)
self.characters = charactersArray
self.bitesPerSymbol = String(charactersArray.count - 1, radix: 2).count
self.maxMessageCount = version.maxBitesPerSection * 3 / bitesPerSymbol
self.maxMessageCount = version.maxBitesPerSection * 3 / bitesPerSymbol - 1
}
func validate(_ text: String) -> Bool {