Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/rt/util/hash.d
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/**
* This module contains the default hash implementation.
* The default hash implementation.
*
* Copyright: Copyright Sean Kelly 2009 - 2009.
* Copyright: Copyright Sean Kelly 2009 - 2016.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about $(YEAR)?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be inaccurate, as the year should be the last year the code was worked on rather than the year the documentation was generated.

* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: Sean Kelly
*/

/* Copyright Sean Kelly 2009 - 2009.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
* Source: $(DRUNTIMESRC src/rt/util/_hash.d)
*/
module rt.util.hash;

Expand All @@ -23,7 +18,13 @@ version( AnyX86 )


@trusted pure nothrow
size_t hashOf( const (void)* buf, size_t len, size_t seed = 0 )
size_t hashOf( const(void)[] buf, size_t seed = 0 )
{
return hashOf(buf.ptr, buf.length, seed);
}

@trusted pure nothrow
size_t hashOf( const(void)* buf, size_t len, size_t seed = 0 )
{
/*
* This is Paul Hsieh's SuperFastHash algorithm, described here:
Expand All @@ -48,12 +49,11 @@ size_t hashOf( const (void)* buf, size_t len, size_t seed = 0 )
// value was incorporated to allow chaining.
auto data = cast(const (ubyte)*) buf;
auto hash = seed;
int rem;

if( len <= 0 || data is null )
if( len == 0 || data is null )
return 0;

rem = len & 3;
int rem = len & 3;
len >>= 2;

for( ; len > 0; len-- )
Expand Down