Skip to content

Commit d62bfb6

Browse files
committed
0.2.0: idiomatic
1 parent 297a27a commit d62bfb6

14 files changed

+6311
-33
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*]
2+
indent_style = space
3+
insert_final_newline = true
4+
indent_size = 2
5+
trim_trailing_whitespace = true

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
meow
3-
tests/*
3+
deps
4+
nim.cfg

.travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
os:
2+
- windows
3+
- linux
4+
- osx
5+
6+
language: c
7+
8+
env:
9+
- BRANCH=1.0.6
10+
11+
cache:
12+
directories:
13+
- "$HOME/.choosenim"
14+
- "$TRAVIS_BUILD_DIR/git"
15+
16+
install:
17+
- curl https://gist.github.com/genotrance/fb53504a4fba88bc5201d3783df5c522/raw/travis.sh -LsSf -o travis.sh
18+
- source travis.sh
19+
20+
script:
21+
- nimble install -y -d
22+
- nimble test

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# meow
2+
13
meow is a [Nim](https://nim-lang.org/) wrapper for the [meow_hash](https://github.com/cmuratori/meow_hash) library.
24

35
`meow` is distributed as a [Nimble](https://github.com/nim-lang/nimble) package and depends on [nimterop](https://github.com/nimterop/nimterop) to generate the wrappers. The `meow_hash` source code is downloaded using Git so having ```git``` in the path is required.
46

5-
__Installation__
7+
## Installation
68

79
`meow` can be installed via [Nimble](https://github.com/nim-lang/nimble):
810

@@ -12,7 +14,7 @@ __Installation__
1214

1315
This will download and install `meow` in the standard Nimble package location, typically ~/.nimble. Once installed, it can be imported into any Nim program.
1416

15-
__Usage__
17+
## Usage
1618

1719
Module documentation can be found [here](https://disruptek.github.io/meow/meow.html)
1820

@@ -22,10 +24,13 @@ import meow
2224
echo MeowFile("path/to/file")
2325
```
2426

25-
__Credits__
27+
## Credits
2628

2729
`meow` wraps the `meow_hash` source code and all licensing terms of [meow_hash](https://github.com/cmuratori/meow_hash/blob/master/LICENSE) apply to the usage of this package.
2830

29-
__Feedback__
31+
## Feedback
3032

3133
`meow` is a work in progress and any feedback or suggestions are welcome. It is hosted on [GitHub](https://github.com/disruptek/meow) with an MIT license so issues, forks and PRs are most appreciated.
34+
35+
## Documentation
36+
See [the documentation for the meow module](https://disruptek.github.io/meow/meow.html) as generated directly from the source.

docs/dochack.js

+4,714
Large diffs are not rendered by default.

docs/meow.html

+425
Large diffs are not rendered by default.

docs/meow.idx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
MEOW_HASH_VERSION meow.html#MEOW_HASH_VERSION meow: MEOW_HASH_VERSION
2+
MEOW_HASH_VERSION_NAME meow.html#MEOW_HASH_VERSION_NAME meow: MEOW_HASH_VERSION_NAME
3+
MEOW_PAGESIZE meow.html#MEOW_PAGESIZE meow: MEOW_PAGESIZE
4+
MEOW_PREFETCH meow.html#MEOW_PREFETCH meow: MEOW_PREFETCH
5+
MEOW_PREFETCH_LIMIT meow.html#MEOW_PREFETCH_LIMIT meow: MEOW_PREFETCH_LIMIT
6+
meow_state meow.html#meow_state meow: meow_state
7+
MeowShiftAdjust meow.html#MeowShiftAdjust meow: MeowShiftAdjust
8+
MeowMaskLen meow.html#MeowMaskLen meow: MeowMaskLen
9+
MeowDefaultSeed meow.html#MeowDefaultSeed meow: MeowDefaultSeed
10+
MeowHash meow.html#MeowHash,pointer,culonglong,pointer meow: MeowHash(Seed128Init: pointer; Len: culonglong; SourceInit: pointer): m128i
11+
MeowBegin meow.html#MeowBegin,ptr.meow_state,pointer meow: MeowBegin(State: ptr meow_state; Seed128: pointer)
12+
MeowAbsorbBlocks meow.html#MeowAbsorbBlocks,ptr.meow_state,culonglong,ptr.cuchar meow: MeowAbsorbBlocks(State: ptr meow_state; BlockCount: culonglong; rax: ptr cuchar)
13+
MeowAbsorb meow.html#MeowAbsorb,ptr.meow_state,culonglong,pointer meow: MeowAbsorb(State: ptr meow_state; Len: culonglong; SourceInit: pointer)
14+
MeowEnd meow.html#MeowEnd,ptr.meow_state,ptr.cuchar meow: MeowEnd(State: ptr meow_state; Store128: ptr cuchar): m128i
15+
MeowExpandSeed meow.html#MeowExpandSeed,culonglong,pointer,ptr.cuchar meow: MeowExpandSeed(InputLen: culonglong; Input: pointer; SeedResult: ptr cuchar)
16+
Meow meow.html#Meow meow: Meow
17+
meowHash meow.html#meowHash meow: meowHash(x: cstring | string): Meow
18+
meowHash meow.html#meowHash,T meow: meowHash[T](x: T): Meow
19+
meowHash meow.html#meowHash,string meow: meowHash(x: string): Meow
20+
`==` meow.html#==,m128i,m128i meow: `==`(a, b: Meow): bool
21+
meowFile meow.html#meowFile,string meow: meowFile(path: string): Meow
22+
toArray meow.html#toArray.c,m128i meow: toArray(h: Meow): seq[uint32]
23+
`$` meow.html#$,m128i meow: `$`(h: Meow): string
24+
hash meow.html#hash,m128i meow: hash(x: Meow): Hash

docs/nimdoc.out.css

+892
Large diffs are not rendered by default.

docs/theindex.html

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4+
<!-- This file is generated by Nim. -->
5+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6+
<head>
7+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8+
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
11+
<!-- Favicon -->
12+
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
13+
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
14+
15+
<!-- Google fonts -->
16+
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
17+
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
18+
19+
<!-- CSS -->
20+
<title>Index</title>
21+
<link rel="stylesheet" type="text/css" href="nimdoc.out.css">
22+
23+
<script type="text/javascript" src="dochack.js"></script>
24+
25+
<script type="text/javascript">
26+
function main() {
27+
var pragmaDots = document.getElementsByClassName("pragmadots");
28+
for (var i = 0; i < pragmaDots.length; i++) {
29+
pragmaDots[i].onclick = function(event) {
30+
// Hide tease
31+
event.target.parentNode.style.display = "none";
32+
// Show actual
33+
event.target.parentNode.nextElementSibling.style.display = "inline";
34+
}
35+
}
36+
37+
const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
38+
function switchTheme(e) {
39+
if (e.target.checked) {
40+
document.documentElement.setAttribute('data-theme', 'dark');
41+
localStorage.setItem('theme', 'dark');
42+
} else {
43+
document.documentElement.setAttribute('data-theme', 'light');
44+
localStorage.setItem('theme', 'light');
45+
}
46+
}
47+
48+
toggleSwitch.addEventListener('change', switchTheme, false);
49+
50+
const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
51+
if (currentTheme) {
52+
document.documentElement.setAttribute('data-theme', currentTheme);
53+
54+
if (currentTheme === 'dark') {
55+
toggleSwitch.checked = true;
56+
}
57+
}
58+
}
59+
</script>
60+
61+
</head>
62+
<body onload="main()">
63+
<div class="document" id="documentId">
64+
<div class="container">
65+
<h1 class="title">Index</h1>
66+
Modules: <a href="meow.html">meow</a>.<br/><p /><h2>API symbols</h2>
67+
<dl><dt><a name="%60%24%60" href="#%60%24%60"><span>`$`:</span></a></dt><dd><ul class="simple">
68+
<li><a class="reference external"
69+
data-doc-search-tag="meow: `$`(h: Meow): string" href="meow.html#%24%2Cm128i">meow: `$`(h: Meow): string</a></li>
70+
</ul></dd>
71+
<dt><a name="%60%3D%3D%60" href="#%60%3D%3D%60"><span>`==`:</span></a></dt><dd><ul class="simple">
72+
<li><a class="reference external"
73+
data-doc-search-tag="meow: `==`(a, b: Meow): bool" href="meow.html#%3D%3D%2Cm128i%2Cm128i">meow: `==`(a, b: Meow): bool</a></li>
74+
</ul></dd>
75+
<dt><a name="hash" href="#hash"><span>hash:</span></a></dt><dd><ul class="simple">
76+
<li><a class="reference external"
77+
data-doc-search-tag="meow: hash(x: Meow): Hash" href="meow.html#hash%2Cm128i">meow: hash(x: Meow): Hash</a></li>
78+
</ul></dd>
79+
<dt><a name="Meow" href="#Meow"><span>Meow:</span></a></dt><dd><ul class="simple">
80+
<li><a class="reference external"
81+
data-doc-search-tag="meow: Meow" href="meow.html#Meow">meow: Meow</a></li>
82+
</ul></dd>
83+
<dt><a name="MeowAbsorb" href="#MeowAbsorb"><span>MeowAbsorb:</span></a></dt><dd><ul class="simple">
84+
<li><a class="reference external"
85+
data-doc-search-tag="meow: MeowAbsorb(State: ptr meow_state; Len: culonglong; SourceInit: pointer)" href="meow.html#MeowAbsorb%2Cptr.meow_state%2Cculonglong%2Cpointer">meow: MeowAbsorb(State: ptr meow_state; Len: culonglong; SourceInit: pointer)</a></li>
86+
</ul></dd>
87+
<dt><a name="MeowAbsorbBlocks" href="#MeowAbsorbBlocks"><span>MeowAbsorbBlocks:</span></a></dt><dd><ul class="simple">
88+
<li><a class="reference external"
89+
data-doc-search-tag="meow: MeowAbsorbBlocks(State: ptr meow_state; BlockCount: culonglong; rax: ptr cuchar)" href="meow.html#MeowAbsorbBlocks%2Cptr.meow_state%2Cculonglong%2Cptr.cuchar">meow: MeowAbsorbBlocks(State: ptr meow_state; BlockCount: culonglong; rax: ptr cuchar)</a></li>
90+
</ul></dd>
91+
<dt><a name="MeowBegin" href="#MeowBegin"><span>MeowBegin:</span></a></dt><dd><ul class="simple">
92+
<li><a class="reference external"
93+
data-doc-search-tag="meow: MeowBegin(State: ptr meow_state; Seed128: pointer)" href="meow.html#MeowBegin%2Cptr.meow_state%2Cpointer">meow: MeowBegin(State: ptr meow_state; Seed128: pointer)</a></li>
94+
</ul></dd>
95+
<dt><a name="MeowDefaultSeed" href="#MeowDefaultSeed"><span>MeowDefaultSeed:</span></a></dt><dd><ul class="simple">
96+
<li><a class="reference external"
97+
data-doc-search-tag="meow: MeowDefaultSeed" href="meow.html#MeowDefaultSeed">meow: MeowDefaultSeed</a></li>
98+
</ul></dd>
99+
<dt><a name="MeowEnd" href="#MeowEnd"><span>MeowEnd:</span></a></dt><dd><ul class="simple">
100+
<li><a class="reference external"
101+
data-doc-search-tag="meow: MeowEnd(State: ptr meow_state; Store128: ptr cuchar): m128i" href="meow.html#MeowEnd%2Cptr.meow_state%2Cptr.cuchar">meow: MeowEnd(State: ptr meow_state; Store128: ptr cuchar): m128i</a></li>
102+
</ul></dd>
103+
<dt><a name="MeowExpandSeed" href="#MeowExpandSeed"><span>MeowExpandSeed:</span></a></dt><dd><ul class="simple">
104+
<li><a class="reference external"
105+
data-doc-search-tag="meow: MeowExpandSeed(InputLen: culonglong; Input: pointer; SeedResult: ptr cuchar)" href="meow.html#MeowExpandSeed%2Cculonglong%2Cpointer%2Cptr.cuchar">meow: MeowExpandSeed(InputLen: culonglong; Input: pointer; SeedResult: ptr cuchar)</a></li>
106+
</ul></dd>
107+
<dt><a name="meowFile" href="#meowFile"><span>meowFile:</span></a></dt><dd><ul class="simple">
108+
<li><a class="reference external"
109+
data-doc-search-tag="meow: meowFile(path: string): Meow" href="meow.html#meowFile%2Cstring">meow: meowFile(path: string): Meow</a></li>
110+
</ul></dd>
111+
<dt><a name="meowHash" href="#meowHash"><span>meowHash:</span></a></dt><dd><ul class="simple">
112+
<li><a class="reference external"
113+
data-doc-search-tag="meow: meowHash(x: cstring | string): Meow" href="meow.html#meowHash">meow: meowHash(x: cstring | string): Meow</a></li>
114+
</ul></dd>
115+
<dt><a name="MeowHash" href="#MeowHash"><span>MeowHash:</span></a></dt><dd><ul class="simple">
116+
<li><a class="reference external"
117+
data-doc-search-tag="meow: MeowHash(Seed128Init: pointer; Len: culonglong; SourceInit: pointer): m128i" href="meow.html#MeowHash%2Cpointer%2Cculonglong%2Cpointer">meow: MeowHash(Seed128Init: pointer; Len: culonglong; SourceInit: pointer): m128i</a></li>
118+
</ul></dd>
119+
<dt><a name="meowHash" href="#meowHash"><span>meowHash:</span></a></dt><dd><ul class="simple">
120+
<li><a class="reference external"
121+
data-doc-search-tag="meow: meowHash(x: string): Meow" href="meow.html#meowHash%2Cstring">meow: meowHash(x: string): Meow</a></li>
122+
<li><a class="reference external"
123+
data-doc-search-tag="meow: meowHash[T](x: T): Meow" href="meow.html#meowHash%2CT">meow: meowHash[T](x: T): Meow</a></li>
124+
</ul></dd>
125+
<dt><a name="MEOW_HASH_VERSION" href="#MEOW_HASH_VERSION"><span>MEOW_HASH_VERSION:</span></a></dt><dd><ul class="simple">
126+
<li><a class="reference external"
127+
data-doc-search-tag="meow: MEOW_HASH_VERSION" href="meow.html#MEOW_HASH_VERSION">meow: MEOW_HASH_VERSION</a></li>
128+
</ul></dd>
129+
<dt><a name="MEOW_HASH_VERSION_NAME" href="#MEOW_HASH_VERSION_NAME"><span>MEOW_HASH_VERSION_NAME:</span></a></dt><dd><ul class="simple">
130+
<li><a class="reference external"
131+
data-doc-search-tag="meow: MEOW_HASH_VERSION_NAME" href="meow.html#MEOW_HASH_VERSION_NAME">meow: MEOW_HASH_VERSION_NAME</a></li>
132+
</ul></dd>
133+
<dt><a name="MeowMaskLen" href="#MeowMaskLen"><span>MeowMaskLen:</span></a></dt><dd><ul class="simple">
134+
<li><a class="reference external"
135+
data-doc-search-tag="meow: MeowMaskLen" href="meow.html#MeowMaskLen">meow: MeowMaskLen</a></li>
136+
</ul></dd>
137+
<dt><a name="MEOW_PAGESIZE" href="#MEOW_PAGESIZE"><span>MEOW_PAGESIZE:</span></a></dt><dd><ul class="simple">
138+
<li><a class="reference external"
139+
data-doc-search-tag="meow: MEOW_PAGESIZE" href="meow.html#MEOW_PAGESIZE">meow: MEOW_PAGESIZE</a></li>
140+
</ul></dd>
141+
<dt><a name="MEOW_PREFETCH" href="#MEOW_PREFETCH"><span>MEOW_PREFETCH:</span></a></dt><dd><ul class="simple">
142+
<li><a class="reference external"
143+
data-doc-search-tag="meow: MEOW_PREFETCH" href="meow.html#MEOW_PREFETCH">meow: MEOW_PREFETCH</a></li>
144+
</ul></dd>
145+
<dt><a name="MEOW_PREFETCH_LIMIT" href="#MEOW_PREFETCH_LIMIT"><span>MEOW_PREFETCH_LIMIT:</span></a></dt><dd><ul class="simple">
146+
<li><a class="reference external"
147+
data-doc-search-tag="meow: MEOW_PREFETCH_LIMIT" href="meow.html#MEOW_PREFETCH_LIMIT">meow: MEOW_PREFETCH_LIMIT</a></li>
148+
</ul></dd>
149+
<dt><a name="MeowShiftAdjust" href="#MeowShiftAdjust"><span>MeowShiftAdjust:</span></a></dt><dd><ul class="simple">
150+
<li><a class="reference external"
151+
data-doc-search-tag="meow: MeowShiftAdjust" href="meow.html#MeowShiftAdjust">meow: MeowShiftAdjust</a></li>
152+
</ul></dd>
153+
<dt><a name="meow_state" href="#meow_state"><span>meow_state:</span></a></dt><dd><ul class="simple">
154+
<li><a class="reference external"
155+
data-doc-search-tag="meow: meow_state" href="meow.html#meow_state">meow: meow_state</a></li>
156+
</ul></dd>
157+
<dt><a name="toArray" href="#toArray"><span>toArray:</span></a></dt><dd><ul class="simple">
158+
<li><a class="reference external"
159+
data-doc-search-tag="meow: toArray(h: Meow): seq[uint32]" href="meow.html#toArray.c%2Cm128i">meow: toArray(h: Meow): seq[uint32]</a></li>
160+
</ul></dd>
161+
</dl>
162+
<div class="row">
163+
<div class="twelve-columns footer">
164+
<span class="nim-sprite"></span>
165+
<br/>
166+
<small style="color: var(--hint);">Made with Nim. Generated: 2020-08-13 18:45:16 UTC</small>
167+
</div>
168+
</div>
169+
</div>
170+
</div>
171+
172+
</body>
173+
</html>

meow.nim

+28-16
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@ static:
2525
]))
2626

2727
cOverride:
28-
type m128i* {.importc: "__m128i", header: "emmintrin.h".} = object
28+
type m128i {.importc: "__m128i", header: "emmintrin.h".} = object
2929

3030
cPassC("-O3 -mavx -maes")
3131
cImport(header, flags = "-E__,_ -c")
3232

33-
proc MeowFile*(path: string): m128i =
33+
type
34+
Meow* = m128i ## meow hash operations use this type
35+
36+
proc meowHash*(x: cstring | string): Meow =
37+
result = MeowHash(addr MeowDefaultSeed, len(x).culonglong, x)
38+
39+
proc meowHash*(x: string): Meow =
40+
result = meowHash(x.cstring)
41+
42+
proc meowHash*[T](x: T): Meow =
43+
result = MeowHash(addr MeowDefaultSeed, sizeof(x).culonglong, x)
44+
45+
proc meowFile*(path: string): Meow =
3446
## Create hash without loading entire file in memory like `MeowHash()`
3547
var
3648
state: meow_state
@@ -52,34 +64,34 @@ proc MeowFile*(path: string): m128i =
5264

5365
f.close()
5466

55-
proc MeowHashesAreEqual*(A, B: m128i): bool =
67+
proc `==`*(a, b: Meow): bool =
5668
## Compare two hashes for equality
5769
({.emit: [
58-
result, " = MeowHashesAreEqual(", A, ", ", B, ");"
70+
result, " = MeowHashesAreEqual(", a, ", ", b, ");"
5971
].})
6072

61-
proc MeowHashToArray*(A: m128i): seq[uint32] =
73+
converter toArray*(h: Meow): seq[uint32] =
6274
## Split 128-bit hash into 4 uint32 values
6375
var s: uint32
64-
({.emit: [s, " = MeowU32From(", A, ", 0);"].})
76+
({.emit: [s, " = MeowU32From(", h, ", 0);"].})
6577
result.add s
66-
({.emit: [s, " = MeowU32From(", A, ", 1);"].})
78+
({.emit: [s, " = MeowU32From(", h, ", 1);"].})
6779
result.add s
68-
({.emit: [s, " = MeowU32From(", A, ", 2);"].})
80+
({.emit: [s, " = MeowU32From(", h, ", 2);"].})
6981
result.add s
70-
({.emit: [s, " = MeowU32From(", A, ", 3);"].})
82+
({.emit: [s, " = MeowU32From(", h, ", 3);"].})
7183
result.add s
7284

73-
proc `$`*(A: m128i): string =
85+
proc `$`*(h: Meow): string =
7486
## Convert hash into a string
75-
let arr = A.MeowHashToArray()
76-
for i in countdown(arr.high, 0):
87+
let arr: seq[uint32] = h
88+
for i in countDown(arr.high, arr.low):
7789
result &= toHex(arr[i])
7890

79-
proc hash*(x: m128i): Hash =
91+
proc hash*(x: Meow): Hash =
8092
## Computes a Hash from `x` for table use
8193
var h: Hash = 0
82-
for i in x.MeowHashToArray():
94+
for i in items(x.toArray):
8395
h = h !& i.int
8496
result = !$h
8597

@@ -89,8 +101,8 @@ when isMainModule:
89101
params = commandLineParams()
90102
case params.len
91103
of 1:
92-
echo MeowFile(params[0])
104+
echo meowFile(params[0])
93105
of 2:
94-
echo MeowHashesAreEqual(MeowFile(params[0]), MeowFile(params[1]))
106+
echo meowFile(params[0]) == meowFile(params[1])
95107
else:
96108
echo "meow file1 [file2]"

meow.nimble

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.1.0"
3+
version = "0.2.0"
44
author = "genotrance"
55
description = "meowhash wrapper for Nim"
66
license = "MIT"

tests/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!.*
3+
!*.nim

tests/test.nim

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import meow
2+
3+
var
4+
hash1 = meowFile(currentSourcePath)
5+
data2 = readFile(currentSourcePath).cstring
6+
hash2 = meowHash(data2)
7+
8+
echo hash1
9+
echo hash2
10+
11+
doAssert hash1 == hash2, "Hashing failed"
12+
13+
assert meowHash("one two three") == meowHash("one two three".cstring)

tests/test1.nim

-11
This file was deleted.

0 commit comments

Comments
 (0)