Skip to content

Commit

Permalink
Update indent
Browse files Browse the repository at this point in the history
  • Loading branch information
daisuke-t-jp committed Apr 26, 2019
1 parent 86c6c4a commit 28bc6a1
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 105 deletions.
6 changes: 3 additions & 3 deletions Sources/MurmurHash/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import CoreFoundation

final class Common {

// MARK: - Enum, Const
enum Endian {
case little
Expand Down Expand Up @@ -72,7 +72,7 @@ extension Common {

// MARK: - Utility(Convert)
extension Common {

static private func UInt8ArrayToUInt<T: FixedWidthInteger>(_ array: [UInt8], index: Int) -> T {
var block: T = 0

Expand All @@ -96,7 +96,7 @@ extension Common {

return block
}


static func UInt32ArrayToHex(_ array: [UInt32]) -> String {
var hex = ""
Expand Down
4 changes: 2 additions & 2 deletions Sources/MurmurHash/MurmurHash3_x64_128.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension MurmurHash3.x64_128 {

var k1: UInt64 = Common.UInt8ArrayToUInt(array, index: i * 2 + 0, endian: Common.endian())
var k2: UInt64 = Common.UInt8ArrayToUInt(array, index: i * 2 + 1, endian: Common.endian())

k1 &*= c1
k1 = Common.rotl(k1, r: 31)
k1 &*= c2
Expand Down Expand Up @@ -305,7 +305,7 @@ extension MurmurHash3.x64_128 {
// fill in tmp buffer
state.memSize = array2.count % 16
state.mem.replaceSubrange(0..<state.memSize,
with: array2[array2.count - state.memSize..<array2.count])
with: array2[array2.count - state.memSize..<array2.count])

for i in 0..<15 {
state.tail.add(array2[array2.count - (15 - i)])
Expand Down
80 changes: 40 additions & 40 deletions Sources/MurmurHash/MurmurHash3_x86_128.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ extension MurmurHash3 {

/// MurmurHash3 x86_128 class
public class x86_128 {

// MARK: - Enum, Const
static private let c1: UInt32 = 0x239b961b
static private let c2: UInt32 = 0xab0e9789
static private let c3: UInt32 = 0x38b34ae5
static private let c4: UInt32 = 0xa1e38b93


// MARK: - Property
private let endian = Common.endian()
private var state = State()
Expand All @@ -28,18 +28,18 @@ extension MurmurHash3 {
reset()
}
}


// MARK: - Life cycle

/// Creates a new instance with the seed.
///
/// - Parameter seed: A seed for generate digest. Default is 0.
public init(_ seed: UInt32 = 0) {
self.seed = seed
reset()
}

}
}

Expand All @@ -60,14 +60,14 @@ extension MurmurHash3.x86_128 {

// MARK: - Utility
extension MurmurHash3.x86_128 {

static private func body(_ h: [UInt32], array: [UInt8]) -> [UInt32] {
let nblocks = array.count / 16
var h1: UInt32 = h[0]
var h2: UInt32 = h[1]
var h3: UInt32 = h[2]
var h4: UInt32 = h[3]

for i in 0..<nblocks {

var k1: UInt32 = Common.UInt8ArrayToUInt(array, index: i * 4, endian: Common.endian())
Expand Down Expand Up @@ -114,7 +114,7 @@ extension MurmurHash3.x86_128 {

return [h1, h2, h3, h4]
}

static private func tailAndFinalize(_ h: [UInt32], tail: [UInt8], len: Int) -> [UInt32] {
var k1: UInt32 = 0
var k2: UInt32 = 0
Expand All @@ -124,124 +124,124 @@ extension MurmurHash3.x86_128 {
var h2: UInt32 = h[1]
var h3: UInt32 = h[2]
var h4: UInt32 = h[3]

/**
* tail
*/
switch len & 15 {
case 15:
k4 ^= UInt32(tail[14]) << 16
fallthrough

case 14:
k4 ^= UInt32(tail[13]) << 8
fallthrough

case 13:
k4 ^= UInt32(tail[12]) << 0
k4 &*= c4
k4 = Common.rotl(k4, r: 18)
k4 &*= c1
h4 ^= k4
fallthrough


case 12:
k3 ^= UInt32(tail[11]) << 24
fallthrough

case 11:
k3 ^= UInt32(tail[10]) << 16
fallthrough

case 10:
k3 ^= UInt32(tail[9]) << 8
fallthrough

case 9:
k3 ^= UInt32(tail[8]) << 0
k3 &*= c3
k3 = Common.rotl(k3, r: 17)
k3 &*= c4
h3 ^= k3
fallthrough


case 8:
k2 ^= UInt32(tail[7]) << 24
fallthrough

case 7:
k2 ^= UInt32(tail[6]) << 16
fallthrough

case 6:
k2 ^= UInt32(tail[5]) << 8
fallthrough

case 5:
k2 ^= UInt32(tail[4]) << 0
k2 &*= c2
k2 = Common.rotl(k2, r: 16)
k2 &*= c3
h2 ^= k2
fallthrough


case 4:
k1 ^= UInt32(tail[3]) << 24
fallthrough

case 3:
k1 ^= UInt32(tail[2]) << 16
fallthrough

case 2:
k1 ^= UInt32(tail[1]) << 8
fallthrough

case 1:
k1 ^= UInt32(tail[0]) << 0
k1 &*= c1
k1 = Common.rotl(k1, r: 15)
k1 &*= c2
h1 ^= k1

default:
break
}


/**
* finalization
*/
h1 ^= UInt32(len)
h2 ^= UInt32(len)
h3 ^= UInt32(len)
h4 ^= UInt32(len)

h1 &+= h2
h1 &+= h3
h1 &+= h4
h2 &+= h1
h3 &+= h1
h4 &+= h1

h1 = Common.fmix32(h1)
h2 = Common.fmix32(h2)
h3 = Common.fmix32(h3)
h4 = Common.fmix32(h4)

h1 &+= h2
h1 &+= h3
h1 &+= h4
h2 &+= h1
h3 &+= h1
h4 &+= h1

return [h1, h2, h3, h4]
}

}


Expand Down Expand Up @@ -318,7 +318,7 @@ extension MurmurHash3.x86_128 {

// MARK: - Digest(Streaming)
extension MurmurHash3.x86_128 {

/// Reset current streaming state to initial.
public func reset() {
state = MurmurHash3.x86_128.State()
Expand Down Expand Up @@ -356,7 +356,7 @@ extension MurmurHash3.x86_128 {
// fill in tmp buffer
state.memSize = array2.count % 16
state.mem.replaceSubrange(0..<state.memSize,
with: array2[array2.count - state.memSize..<array2.count])
with: array2[array2.count - state.memSize..<array2.count])

for i in 0..<15 {
state.tail.add(array2[array2.count - (15 - i)])
Expand Down Expand Up @@ -386,8 +386,8 @@ extension MurmurHash3.x86_128 {
tail2.removeFirst(tail2.count - state.totalLen % 16)

let h = MurmurHash3.x86_128.tailAndFinalize(state.h,
tail: tail2,
len: state.totalLen)
tail: tail2,
len: state.totalLen)

return h
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/MurmurHash/MurmurHash3_x86_32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension MurmurHash3.x86_32 {

return h1
}

static private func tailAndFinalize(_ h1: UInt32, tail: [UInt8], len: Int) -> UInt32 {
var k1: UInt32 = 0
var h2 = h1
Expand Down Expand Up @@ -228,7 +228,7 @@ extension MurmurHash3.x86_32 {
// fill in tmp buffer
state.memSize = array2.count % 4
state.mem.replaceSubrange(0..<state.memSize,
with: array2[array2.count - state.memSize..<array2.count])
with: array2[array2.count - state.memSize..<array2.count])

for i in 0..<3 {
state.tail.add(array2[array2.count - (3 - i)])
Expand Down Expand Up @@ -270,5 +270,5 @@ extension MurmurHash3.x86_32 {
let h = digest()
return Common.UInt32ArrayToHex([h])
}

}
28 changes: 14 additions & 14 deletions Tests/MurmurHashTests/MurmurHashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ class MurmurHashTests: XCTestCase {
("test_x86_128FileWithSeed", test_x86_128FileWithSeed),
("test_x64_128File", test_x64_128File),
("test_x64_128FileWithSeed", test_x64_128FileWithSeed),
]
]



override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

// MARK: - Overload
func test_x86_32Overload() {
Expand Down Expand Up @@ -90,7 +90,7 @@ class MurmurHashTests: XCTestCase {
XCTAssertEqual(MurmurHash3.x86_32.digest("Hello World! Hello World!", seed: 0x7fffffff), 0x47fcc800)
XCTAssertEqual(MurmurHash3.x86_32.digestHex("Hello World! Hello World!", seed: 0x7fffffff).lowercased(), "47fcc800")
}

func test_x86_128OneShot() {
XCTAssertEqual(MurmurHash3.x86_128.digest("")[0], 0x00000000)
XCTAssertEqual(MurmurHash3.x86_128.digest("")[1], 0x00000000)
Expand Down Expand Up @@ -118,7 +118,7 @@ class MurmurHashTests: XCTestCase {
XCTAssertEqual(MurmurHash3.x86_128.digest("Hello World! Hello World!", seed: 0x7fffffff)[3], 0xb015261f)
XCTAssertEqual(MurmurHash3.x86_128.digestHex("Hello World! Hello World!", seed: 0x7fffffff).lowercased(), "d1ab28e6f4fc514c5e0df753b015261f")
}

func test_x64_128OneShot() {
XCTAssertEqual(MurmurHash3.x64_128.digest("")[0], 0x0000000000000000)
XCTAssertEqual(MurmurHash3.x64_128.digest("")[1], 0x0000000000000000)
Expand All @@ -128,7 +128,7 @@ class MurmurHashTests: XCTestCase {
XCTAssertEqual(MurmurHash3.x64_128.digest("Hello World! Hello World!")[1], 0x8d0d724eecb72e66)
XCTAssertEqual(MurmurHash3.x64_128.digestHex("Hello World! Hello World!").lowercased(), "e881a28e49269b1e8d0d724eecb72e66")
}

func test_x64_128OneShotWithSeed() {
XCTAssertEqual(MurmurHash3.x64_128.digest("", seed: 0x7fffffff)[0], 0x656ac7570e166c3f)
XCTAssertEqual(MurmurHash3.x64_128.digest("", seed: 0x7fffffff)[1], 0xc34c2ca1ed468e40)
Expand All @@ -138,7 +138,7 @@ class MurmurHashTests: XCTestCase {
XCTAssertEqual(MurmurHash3.x64_128.digest("Hello World! Hello World!", seed: 0x7fffffff)[1], 0xfbd535aec6551aab)
XCTAssertEqual(MurmurHash3.x64_128.digestHex("Hello World! Hello World!", seed: 0x7fffffff).lowercased(), "6028586a8c3df476fbd535aec6551aab")
}



// MARK: - Update
Expand Down Expand Up @@ -287,7 +287,7 @@ class MurmurHashTests: XCTestCase {
mmh.seed = seed // Reset when setting seed.
XCTAssertEqual(mmh.digest(), MurmurHash3.x86_32(seed).digest())
}

func test_x86_128Reset() {
let seed = UInt32(0x7fffffff)
let mmh = MurmurHash3.x86_128()
Expand All @@ -300,7 +300,7 @@ class MurmurHashTests: XCTestCase {
mmh.seed = seed // Reset when setting seed.
XCTAssertEqual(mmh.digest(), MurmurHash3.x86_128(seed).digest())
}

func test_x64_128Reset() {
let seed = UInt32(0x7fffffff)
let mmh = MurmurHash3.x64_128()
Expand Down
Loading

0 comments on commit 28bc6a1

Please sign in to comment.