<commit_before>
import Prefix from './prefix';
import IpBits from './ip_bits';
import IpVersion from './ip_version';
import Ipv4 from './ipv4';
import Ipv6 from './ipv6';
import Ipv6Mapped from './ipv6_mapped';

import Crunchy from './crunchy';

export interface Is {
    (source: IPAddress): boolean;
}

export interface ToIpv4 {
    (source: IPAddress): IPAddress;
}


export interface EachFn {
    (source: IPAddress): void;
}

export class ResultCrunchyParts {
    public crunchy: Crunchy;
    public parts: number;

    constructor(crunchy: Crunchy, parts: number) {
        this.crunchy = crunchy;
        this.parts = parts;
        // console.log("ResultCrunchyParts:", this);
    }
}

export class IPAddress {
    ip_bits: IpBits;
    host_address: Crunchy;
    prefix: Prefix;
    mapped: IPAddress;
    vt_is_private: Is;
    vt_is_loopback: Is;
    vt_to_ipv6: ToIpv4;

    constructor(obj: { [id: string]: any }) {
        this.ip_bits = obj['ip_bits'];
        this.host_address = obj['host_address'];
        this.prefix = obj['prefix'];
        this.mapped = obj['mapped'];
        this.vt_is_private = obj['vt_is_private'];
        this.vt_is_loopback = obj['vt_is_loopback'];
        this.vt_to_ipv6 = obj['vt_to_ipv6'];
    }

    public clone(): IPAddress {
        let mapped: IPAddress = null;
        if (this.mapped) {
            mapped = this.mapped.clone();
        }
        return new IPAddress({
            ip_bits: this.ip_bits.clone(),
            host_address: this.host_address.clone(),
            prefix: this.prefix.clone(),
            mapped: mapped,
            vt_is_private: this.vt_is_private,
            vt_is_loopback: this.vt_is_loopback,
            vt_to_ipv6: this.vt_to_ipv6
        });
    }

    public lt(oth: IPAddress): boolean {
        return this.cmp(oth) < 0;
    }

    public lte(oth: IPAddress): boolean {
        return this.cmp(oth) <= 0;
    }

    public gt(oth: IPAddress): boolean {
      return this.cmp(oth) > 1;
    }

    public gte(oth: IPAddress): boolean {
        return this.cmp(oth) >= 0;
    }

    public cmp(oth: IPAddress): number {
        if (this.ip_bits.version != oth.ip_bits.version) {
            if (this.ip_bits.version == IpVersion.V6) {
                return 1;
            }
            return -1;
        }
        //let adr_diff = this.host_address - oth.host_address;
        let hostCmp = this.host_address.compare(oth.host_address);
        if (hostCmp != 0) {
            return hostCmp;
        }
        return this.prefix.cmp(oth.prefix);<commit_msg>* fix a 0 and 1 mixture<commit_after>
import Prefix from './prefix';
import IpBits from './ip_bits';
import IpVersion from './ip_version';
import Ipv4 from './ipv4';
import Ipv6 from './ipv6';
import Ipv6Mapped from './ipv6_mapped';

import Crunchy from './crunchy';

export interface Is {
    (source: IPAddress): boolean;
}

export interface ToIpv4 {
    (source: IPAddress): IPAddress;
}


export interface EachFn {
    (source: IPAddress): void;
}

export class ResultCrunchyParts {
    public crunchy: Crunchy;
    public parts: number;

    constructor(crunchy: Crunchy, parts: number) {
        this.crunchy = crunchy;
        this.parts = parts;
        // console.log("ResultCrunchyParts:", this);
    }
}

export class IPAddress {
    ip_bits: IpBits;
    host_address: Crunchy;
    prefix: Prefix;
    mapped: IPAddress;
    vt_is_private: Is;
    vt_is_loopback: Is;
    vt_to_ipv6: ToIpv4;

    constructor(obj: { [id: string]: any }) {
        this.ip_bits = obj['ip_bits'];
        this.host_address = obj['host_address'];
        this.prefix = obj['prefix'];
        this.mapped = obj['mapped'];
        this.vt_is_private = obj['vt_is_private'];
        this.vt_is_loopback = obj['vt_is_loopback'];
        this.vt_to_ipv6 = obj['vt_to_ipv6'];
    }

    public clone(): IPAddress {
        let mapped: IPAddress = null;
        if (this.mapped) {
            mapped = this.mapped.clone();
        }
        return new IPAddress({
            ip_bits: this.ip_bits.clone(),
            host_address: this.host_address.clone(),
            prefix: this.prefix.clone(),
            mapped: mapped,
            vt_is_private: this.vt_is_private,
            vt_is_loopback: this.vt_is_loopback,
            vt_to_ipv6: this.vt_to_ipv6
        });
    }

    public lt(oth: IPAddress): boolean {
        return this.cmp(oth) < 0;
    }

    public lte(oth: IPAddress): boolean {
        return this.cmp(oth) <= 0;
    }

    public gt(oth: IPAddress): boolean {
      return this.cmp(oth) > 0;
    }

    public gte(oth: IPAddress): boolean {
        return this.cmp(oth) >= 0;
    }

    public cmp(oth: IPAddress): number {
        if (this.ip_bits.version != oth.ip_bits.version) {
            if (this.ip_bits.version == IpVersion.V6) {
                return 1;
            }
            return -1;
        }
        //let adr_diff = this.host_address - oth.host_address;
        let hostCmp = this.host_address.compare(oth.host_address);
        if (hostCmp != 0) {
            return hostCmp;
        }
        return this.prefix.cmp(oth.prefix);
{'fraction_non_alphanumeric': 0.1231940648184303, 'fraction_numerical': 0.008590394377196407, 'mean_word_length': 2.224040276903713, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2838410', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1706, 'n_words': 375}