Nilsimsa
in package
The MIT License (MIT)
Copyright (c) 2015 Bill Eager
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Table of Contents
- TRAN = [0x2, 0xd6, 0x9e, 0x6f, 0xf9, 0x1d, 0x4, 0xab, 0xd0, 0x22, 0x16, 0x1f, 0xd8, 0x73, 0xa1, 0xac, 0x3b, 0x70, 0x62, 0x96, 0x1e, 0x6e, 0x8f, 0x39, 0x9d, 0x5, 0x14, 0x4a, 0xa6, 0xbe, 0xae, 0xe, 0xcf, 0xb9, 0x9c, 0x9a, 0xc7, 0x68, 0x13, 0xe1, 0x2d, 0xa4, 0xeb, 0x51, 0x8d, 0x64, 0x6b, 0x50, 0x23, 0x80, 0x3, 0x41, 0xec, 0xbb, 0x71, 0xcc, 0x7a, 0x86, 0x7f, 0x98, 0xf2, 0x36, 0x5e, 0xee, 0x8e, 0xce, 0x4f, 0xb8, 0x32, 0xb6, 0x5f, 0x59, 0xdc, 0x1b, 0x31, 0x4c, 0x7b, 0xf0, 0x63, 0x1, 0x6c, 0xba, 0x7, 0xe8, 0x12, 0x77, 0x49, 0x3c, 0xda, 0x46, 0xfe, 0x2f, 0x79, 0x1c, 0x9b, 0x30, 0xe3, 0x0, 0x6, 0x7e, 0x2e, 0xf, 0x38, 0x33, 0x21, 0xad, 0xa5, 0x54, 0xca, 0xa7, 0x29, 0xfc, 0x5a, 0x47, 0x69, 0x7d, 0xc5, 0x95, 0xb5, 0xf4, 0xb, 0x90, 0xa3, 0x81, 0x6d, 0x25, 0x55, 0x35, 0xf5, 0x75, 0x74, 0xa, 0x26, 0xbf, 0x19, 0x5c, 0x1a, 0xc6, 0xff, 0x99, 0x5d, 0x84, 0xaa, 0x66, 0x3e, 0xaf, 0x78, 0xb3, 0x20, 0x43, 0xc1, 0xed, 0x24, 0xea, 0xe6, 0x3f, 0x18, 0xf3, 0xa0, 0x42, 0x57, 0x8, 0x53, 0x60, 0xc3, 0xc0, 0x83, 0x40, 0x82, 0xd7, 0x9, 0xbd, 0x44, 0x2a, 0x67, 0xa8, 0x93, 0xe0, 0xc2, 0x56, 0x9f, 0xd9, 0xdd, 0x85, 0x15, 0xb4, 0x8a, 0x27, 0x28, 0x92, 0x76, 0xde, 0xef, 0xf8, 0xb2, 0xb7, 0xc9, 0x3d, 0x45, 0x94, 0x4b, 0x11, 0xd, 0x65, 0xd5, 0x34, 0x8b, 0x91, 0xc, 0xfa, 0x87, 0xe9, 0x7c, 0x5b, 0xb1, 0x4d, 0xe5, 0xd4, 0xcb, 0x10, 0xa2, 0x17, 0x89, 0xbc, 0xdb, 0xb0, 0xe2, 0x97, 0x88, 0x52, 0xf7, 0x48, 0xd3, 0x61, 0x2c, 0x3a, 0x2b, 0xd1, 0x8c, 0xfb, 0xf1, 0xcd, 0xe4, 0x6a, 0xe7, 0xa9, 0xfd, 0xc4, 0x37, 0xc8, 0xd2, 0xf6, 0xdf, 0x58, 0x72, 0x4e]
- Tran53 hash constant
- __construct() : mixed
- Constructor
- computeDigest() : mixed
- Using a threshold (mean of the accumulator), computes the nilsimsa digest after completion. Sets complete flag to true and stores result in $this->digest
- digest() : array<string|int, mixed>
- Returns the digest as an array. Computes it if it isn't computed already.
- hash() : mixed
- hexDigest() : string
- Returns the digest as a hex string. Computes it if it isn't computed already.
- process() : mixed
- Computes the hash of all of the trigrams in the chunk using a window of length 5
- tranHash() : int
- Implementation of the Tran53 hash algorithm
Constants
TRAN
Tran53 hash constant
public
array<string|int, mixed>
TRAN
= [0x2, 0xd6, 0x9e, 0x6f, 0xf9, 0x1d, 0x4, 0xab, 0xd0, 0x22, 0x16, 0x1f, 0xd8, 0x73, 0xa1, 0xac, 0x3b, 0x70, 0x62, 0x96, 0x1e, 0x6e, 0x8f, 0x39, 0x9d, 0x5, 0x14, 0x4a, 0xa6, 0xbe, 0xae, 0xe, 0xcf, 0xb9, 0x9c, 0x9a, 0xc7, 0x68, 0x13, 0xe1, 0x2d, 0xa4, 0xeb, 0x51, 0x8d, 0x64, 0x6b, 0x50, 0x23, 0x80, 0x3, 0x41, 0xec, 0xbb, 0x71, 0xcc, 0x7a, 0x86, 0x7f, 0x98, 0xf2, 0x36, 0x5e, 0xee, 0x8e, 0xce, 0x4f, 0xb8, 0x32, 0xb6, 0x5f, 0x59, 0xdc, 0x1b, 0x31, 0x4c, 0x7b, 0xf0, 0x63, 0x1, 0x6c, 0xba, 0x7, 0xe8, 0x12, 0x77, 0x49, 0x3c, 0xda, 0x46, 0xfe, 0x2f, 0x79, 0x1c, 0x9b, 0x30, 0xe3, 0x0, 0x6, 0x7e, 0x2e, 0xf, 0x38, 0x33, 0x21, 0xad, 0xa5, 0x54, 0xca, 0xa7, 0x29, 0xfc, 0x5a, 0x47, 0x69, 0x7d, 0xc5, 0x95, 0xb5, 0xf4, 0xb, 0x90, 0xa3, 0x81, 0x6d, 0x25, 0x55, 0x35, 0xf5, 0x75, 0x74, 0xa, 0x26, 0xbf, 0x19, 0x5c, 0x1a, 0xc6, 0xff, 0x99, 0x5d, 0x84, 0xaa, 0x66, 0x3e, 0xaf, 0x78, 0xb3, 0x20, 0x43, 0xc1, 0xed, 0x24, 0xea, 0xe6, 0x3f, 0x18, 0xf3, 0xa0, 0x42, 0x57, 0x8, 0x53, 0x60, 0xc3, 0xc0, 0x83, 0x40, 0x82, 0xd7, 0x9, 0xbd, 0x44, 0x2a, 0x67, 0xa8, 0x93, 0xe0, 0xc2, 0x56, 0x9f, 0xd9, 0xdd, 0x85, 0x15, 0xb4, 0x8a, 0x27, 0x28, 0x92, 0x76, 0xde, 0xef, 0xf8, 0xb2, 0xb7, 0xc9, 0x3d, 0x45, 0x94, 0x4b, 0x11, 0xd, 0x65, 0xd5, 0x34, 0x8b, 0x91, 0xc, 0xfa, 0x87, 0xe9, 0x7c, 0x5b, 0xb1, 0x4d, 0xe5, 0xd4, 0xcb, 0x10, 0xa2, 0x17, 0x89, 0xbc, 0xdb, 0xb0, 0xe2, 0x97, 0x88, 0x52, 0xf7, 0x48, 0xd3, 0x61, 0x2c, 0x3a, 0x2b, 0xd1, 0x8c, 0xfb, 0xf1, 0xcd, 0xe4, 0x6a, 0xe7, 0xa9, 0xfd, 0xc4, 0x37, 0xc8, 0xd2, 0xf6, 0xdf, 0x58, 0x72, 0x4e]
Methods
__construct()
Constructor
public
__construct([string $data = null ][, mixed $length = null ]) : mixed
Parameters
- $data : string = null
-
The data to process
- $length : mixed = null
Return values
mixed —computeDigest()
Using a threshold (mean of the accumulator), computes the nilsimsa digest after completion. Sets complete flag to true and stores result in $this->digest
public
computeDigest() : mixed
Return values
mixed —digest()
Returns the digest as an array. Computes it if it isn't computed already.
public
digest() : array<string|int, mixed>
Return values
array<string|int, mixed> —The digest
hash()
public
static hash(mixed $data[, mixed $length = 256 ]) : mixed
Parameters
- $data : mixed
- $length : mixed = 256
Return values
mixed —hexDigest()
Returns the digest as a hex string. Computes it if it isn't computed already.
public
hexDigest() : string
Return values
string —The digest
process()
Computes the hash of all of the trigrams in the chunk using a window of length 5
public
process(string $chunk) : mixed
Parameters
- $chunk : string
-
The chunk to process
Return values
mixed —tranHash()
Implementation of the Tran53 hash algorithm
public
tranHash(int $a, int $b, int $c, int $n) : int
Parameters
- $a : int
-
Input A
- $b : int
-
Input B
- $c : int
-
Input C
- $n : int
-
Input N