<commit_before>//
//  Thali CordovaPlugin
//  PeerIdentifier.swift
//
//  Copyright (C) Microsoft. All rights reserved.
//  Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//

import Foundation
import MultipeerConnectivity

public enum PeerIdentifierError: String, ErrorType {
    case WrongDataFormat
}

///Peer identifier for with generations
public struct PeerIdentifier {
    ///UUID identifier of peer
    public let uuid: String
    ///generation of peer.
    public let generation: Int

    public init() {
        uuid = NSUUID().UUIDString
        generation = 1
    }

    private init(uuidIdentifier: String, generation: Int) {
        self.uuid = uuidIdentifier
        self.generation = generation
    }

    public init(stringValue: String) throws {
        let parts = stringValue.characters.split {
             $0 == ":"
             }.map(String.init)
        guard parts.count == 2 else {
            throw PeerIdentifierError.WrongDataFormat
        }
        guard let generation = Int(parts[1]) else {
            throw PeerIdentifierError.WrongDataFormat
        }
        self.uuid = parts[0]
        self.generation = generation
    }

    public func nextGenerationPeer() -> PeerIdentifier {
        return PeerIdentifier(uuidIdentifier: uuid, generation: generation + 1)
    }

    public var stringValue: String {
        return "\(uuid):\(generation)"
    }
}

extension PeerIdentifier {
    var mcPeer: MCPeerID {
        return MCPeerID(displayName: uuid)
    }
}<commit_msg>changed generation format to hexadecimal<commit_after>//
//  Thali CordovaPlugin
//  PeerIdentifier.swift
//
//  Copyright (C) Microsoft. All rights reserved.
//  Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//

import Foundation
import MultipeerConnectivity

public enum PeerIdentifierError: String, ErrorType {
    case WrongDataFormat
}

///Peer identifier for with generations
public struct PeerIdentifier {
    ///UUID identifier of peer
    public let uuid: String
    ///generation of peer.
    public let generation: Int

    public init() {
        uuid = NSUUID().UUIDString
        generation = 0
    }

    private init(uuidIdentifier: String, generation: Int) {
        self.uuid = uuidIdentifier
        self.generation = generation
    }

    public init(stringValue: String) throws {
        let parts = stringValue.characters.split {
             $0 == ":"
             }.map(String.init)
        guard parts.count == 2 else {
            throw PeerIdentifierError.WrongDataFormat
        }
        guard let generation = Int(parts[1], radix: 16) else {
            throw PeerIdentifierError.WrongDataFormat
        }
        self.uuid = parts[0]
        self.generation = generation
    }

    public func nextGenerationPeer() -> PeerIdentifier {
        return PeerIdentifier(uuidIdentifier: uuid, generation: generation + 1)
    }

    public var stringValue: String {
        return "\(uuid):\(String(generation, radix: 16))"
    }
}

extension PeerIdentifier {
    var mcPeer: MCPeerID {
        return MCPeerID(displayName: uuid)
    }
}
{'fraction_non_alphanumeric': 0.08681975463982385, 'fraction_numerical': 0.0050330292544825414, 'mean_word_length': 2.4678298800436207, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4622505', 'n_tokens_mistral': 877, 'n_tokens_neox': 829, 'n_words': 258}