Skip to content

Commit

Permalink
pointer of String
Browse files Browse the repository at this point in the history
  • Loading branch information
hros committed Nov 27, 2022
1 parent 2f2346a commit 0cdf431
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "XXhash"
uuid = "137af188-b1ec-11e9-0b40-31ed9142ae64"
version = "0.8.0"
version = "0.8.1"

[deps]
CBinding = "d43a6710-96b8-4a2d-833c-c424785e5374"
Expand All @@ -9,5 +9,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
xxHash_jll = "5fdcd639-92d1-5a06-bf6b-28f2061df1a9"

[compat]
julia = "^1.0.0"
CBinding = "^1.0.9"
julia = "^1.0.0"
50 changes: 25 additions & 25 deletions src/XXhash.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Compute a hash of any object `d` using the 32 bit [xxHash](http://cyan4973.githu
# Examples
```julia-repl
julia> xxh32("abc")
0x9e84ce64
0x32d153ff
julia> xxh32([1, 2, 3])
0x2a1c9a49
```
"""
@inline xxh32(data::Array, seed::Union{Int32,UInt32}=UInt32(0))::UInt32 = libxxhash.XXH32(data, sizeof(data), seed % UInt32)
@inline xxh32(data::Union{Array,String}, seed::Union{Int32,UInt32}=UInt32(0))::UInt32 = GC.@preserve data libxxhash.XXH32(pointer(data), sizeof(data), seed % UInt32)
@inline xxh32(data::Any, seed::Union{Int32,UInt32}=UInt32(0))::UInt32 = libxxhash.XXH32(Ref(data), sizeof(data), seed % UInt32)


Expand All @@ -49,13 +49,13 @@ Compute a hash of any object `d` using the 64 bit [xxHash](http://cyan4973.githu
# Examples
```julia-repl
julia> xxh64("abc")
0xf4740f6daf499e0e
0x44bc2cf5ad770999
julia> xxh64("abc")
julia> xxh64([1,2,3])
0x8799e152e5c0cdfa
```
"""
@inline xxh64(data::Array, seed::Union{Int64,UInt64}=0)::UInt64 = libxxhash.XXH64(data, sizeof(data), seed % UInt32)
@inline xxh64(data::Union{Array,String}, seed::Union{Int64,UInt64}=0)::UInt64 = GC.@preserve data libxxhash.XXH64(pointer(data), sizeof(data), seed % UInt32)
@inline xxh64(data::Any, seed::Union{Int64,UInt64}=0)::UInt64 = libxxhash.XXH64(Ref(data), sizeof(data), seed % UInt32)


Expand Down Expand Up @@ -86,8 +86,9 @@ See also: [`xxhash_digest`](@ref), [`XXH32stream`](@ref), [`XXH64stream`](@ref),
"""
@inline xxhash_update(stream::XXH32stream, data::Any)::Cint =
libxxhash.libxxhash.XXH32_update(stream.state_ptr, Ref(data), sizeof(data))
@inline xxhash_update(stream::XXH32stream, data::Array)::Cint =
libxxhash.libxxhash.XXH32_update(stream.state_ptr, data, sizeof(data))

@inline xxhash_update(stream::XXH32stream, data::Union{Array,String})::Cint =
GC.@preserve data libxxhash.libxxhash.XXH32_update(stream.state_ptr, pointer(data), sizeof(data))

"""
xxhash_digest(xxhash_stream)
Expand Down Expand Up @@ -145,8 +146,9 @@ mutable struct XXH64stream
end
@inline xxhash_update(stream::XXH64stream, data::Any)::Cint =
libxxhash.XXH64_update(stream.state_ptr, Ref(data), sizeof(data))
@inline xxhash_update(stream::XXH64stream, data::Array)::Cint =
libxxhash.XXH64_update(stream.state_ptr, data, sizeof(data))

@inline xxhash_update(stream::XXH64stream, data::Union{Array,String})::Cint =
GC.@preserve data libxxhash.XXH64_update(stream.state_ptr, pointer(data), sizeof(data))

@inline xxhash_digest(stream::XXH64stream)::UInt64 =
libxxhash.XXH64_digest(stream.state_ptr)
Expand Down Expand Up @@ -209,22 +211,22 @@ The function has 3 methods:
# Examples
```julia-repl
julia> xxh3_64("abc")
0x959ec3e5ffe12e7f
0x78af5f94892f3950
julia> xxh3_64("abc", UInt64(0))
0x959ec3e5ffe12e7f
0x78af5f94892f3950
julia> xxh3_64(collect(100:200))
0xff8cb2af8e253283
```
"""
@inline xxh3_64(data::Array)::UInt64 = libxxhash.XXH3_64bits(data, sizeof(data))
@inline xxh3_64(data::Union{Array,String})::UInt64 = GC.@preserve data libxxhash.XXH3_64bits(pointer(data), sizeof(data))
@inline xxh3_64(data::Any)::UInt64 = libxxhash.XXH3_64bits(Ref(data), sizeof(data))

@inline xxh3_64(data::Array, seed::libxxhash.XXH64_hash_t)::UInt64 = libxxhash.XXH3_64bits_withSeed(Ref(data), sizeof(data), seed)
@inline xxh3_64(data::Union{Array,String}, seed::libxxhash.XXH64_hash_t)::UInt64 = GC.@preserve data libxxhash.XXH3_64bits_withSeed(pointer(data), sizeof(data), seed)
@inline xxh3_64(data::Any, seed::libxxhash.XXH64_hash_t)::UInt64 = libxxhash.XXH3_64bits_withSeed(Ref(data), sizeof(data), seed)

@inline xxh3_64(data::Array, secret::Array)::UInt64 = libxxhash.XXH3_64bits_withSecret(Ref(data), sizeof(data), secret, sizeof(secret))
@inline xxh3_64(data::Union{Array,String}, secret::Array)::UInt64 = GC.@preserve data libxxhash.XXH3_64bits_withSecret(pointer(data), sizeof(data), secret, sizeof(secret))
@inline xxh3_64(data::Any, secret::Array)::UInt64 = libxxhash.XXH3_64bits_withSecret(Ref(data), sizeof(data), secret, sizeof(secret))


Expand Down Expand Up @@ -252,22 +254,22 @@ The function has 3 methods:
# Examples
```julia-repl
julia> xxh3_128("abc")
0xc9eacdcf5f8093fc959ec3e5ffe12e7f
0x06b05ab6733a618578af5f94892f3950
julia> xxh3_128("abc", UInt64(0))
0xc9eacdcf5f8093fc959ec3e5ffe12e7f
0x06b05ab6733a618578af5f94892f3950
julia> xxh3_128(collect(100:200))
0xc1d19d1716502f1cff8cb2af8e253283
```
"""
@inline xxh3_128(data::Array)::UInt128 = XXH128_hash_to_U128(libxxhash.XXH3_128bits(data, sizeof(data)))
@inline xxh3_128(data::Union{Array,String})::UInt128 = GC.@preserve data XXH128_hash_to_U128(libxxhash.XXH3_128bits(pointer(data), sizeof(data)))
@inline xxh3_128(data::Any)::UInt128 = XXH128_hash_to_U128(libxxhash.XXH3_128bits(Ref(data), sizeof(data)))

@inline xxh3_128(data::Array, seed::libxxhash.XXH64_hash_t)::UInt128 = XXH128_hash_to_U128(libxxhash.XXH3_128bits_withSeed(Ref(data), sizeof(data), seed))
@inline xxh3_128(data::Union{Array,String}, seed::libxxhash.XXH64_hash_t)::UInt128 = GC.@preserve data XXH128_hash_to_U128(libxxhash.XXH3_128bits_withSeed(pointer(data), sizeof(data), seed))
@inline xxh3_128(data::Any, seed::libxxhash.XXH64_hash_t)::UInt128 = XXH128_hash_to_U128(libxxhash.XXH3_128bits_withSeed(Ref(data), sizeof(data), seed))

@inline xxh3_128(data::Array, secret::Array)::UInt128 = XXH128_hash_to_U128(libxxhash.XXH3_128bits_withSecret(Ref(data), sizeof(data), secret, sizeof(secret)))
@inline xxh3_128(data::Union{Array,String}, secret::Array)::UInt128 = GC.@preserve data XXH128_hash_to_U128(libxxhash.XXH3_128bits_withSecret(pointer(data), sizeof(data), secret, sizeof(secret)))
@inline xxh3_128(data::Any, secret::Array)::UInt64 = XXH128_hash_to_U128(libxxhash.XXH3_128bits_withSecret(Ref(data), sizeof(data), secret, sizeof(secret)))


Expand Down Expand Up @@ -300,11 +302,10 @@ mutable struct XXH3_64stream
end
end


@inline xxhash_update(stream::XXH3_64stream, data::Any)::Cint =
libxxhash.XXH3_64bits_update(stream.state_ptr, Ref(data), sizeof(data))
@inline xxhash_update(stream::XXH3_64stream, data::Array)::Cint =
libxxhash.XXH3_64bits_update(stream.state_ptr, data, sizeof(data))
@inline xxhash_update(stream::XXH3_64stream, data::Union{Array,String})::Cint =
GC.@preserve data libxxhash.XXH3_64bits_update(stream.state_ptr, pointer(data), sizeof(data))

@inline xxhash_digest(stream::XXH3_64stream)::UInt64 =
libxxhash.XXH3_64bits_digest(stream.state_ptr)
Expand Down Expand Up @@ -339,11 +340,10 @@ mutable struct XXH3_128stream
end
end


@inline xxhash_update(stream::XXH3_128stream, data::Any)::Cint =
libxxhash.XXH3_128bits_update(stream.state_ptr, Ref(data), sizeof(data))
@inline xxhash_update(stream::XXH3_128stream, data::Array)::Cint =
libxxhash.XXH3_128bits_update(stream.state_ptr, data, sizeof(data))
@inline xxhash_update(stream::XXH3_128stream, data::Union{Array,String})::Cint =
GC.@preserve data libxxhash.XXH3_128bits_update(stream.state_ptr, pointer(data), sizeof(data))

@inline xxhash_digest(stream::XXH3_128stream)::UInt128 =
XXH128_hash_to_U128(libxxhash.XXH3_128bits_digest(stream.state_ptr))
Expand Down

2 comments on commit 0cdf431

@hros
Copy link
Owner Author

@hros hros commented on 0cdf431 Nov 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72945

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.1 -m "<description of version>" 0cdf4318344fe902ebcb285a08d7f7aee3e5f3cc
git push origin v0.8.1

Please sign in to comment.