Implementing the Hashable Protocol in Swift with the DJB hash function
The Hashable protocol has only one single requirement:


  Axiom: x == y implies x.hashValue == y.hashValue.


So let's start with your implementation of ==:


// Hashable also needs struct to conform to Equatable protocol
func ==(left: ScalarString, right: ScalarString) -&gt; Bool {

    if left.length != right.length {
        return false
    }

    for var i = 0; i &lt; left.length; ++i {
        if left.charAt(i) != right.charAt(i) {
            return false
        }
    }

    return true
}



Looking up the definitions of length and charAt() it is clear
that here simply the left.scalarArray and right.scalarArray
arrays are checked for equality. So the operator can equivalently
but simpler be implemented as

// Hashable also needs struct to conform to Equatable protocol
func ==(left: ScalarString, right: ScalarString) -&gt; Bool {
    return left.scalarArray == right.scalarArray
}


From this representation it becomes obvious that your hashValue
implementation is correct: It is computed from the scalarArray
property, so equal objects have the same hash value.

The hashValue computed property can be simplified using
reduce(), note also that for a read-only property, you need
not put the getter method inside a get { } block:

// hashValue (to implement Hashable protocol)
var hashValue: Int {
    return self.scalarArray.reduce(5381) {
        ($0 &lt;&lt; 5) &amp;+ $0 &amp;+ Int($1)
    }
}


A different question would be how "good" the hash is.
The Swift language does not make any requirements here. Always
returning 0 would be valid, but of course ineffective when
building large dictionaries.

It may be interesting in this context that the hash value of 
the Foundation type NSArray is simply the number of elements,
regardless of the contents.

In your case, the DJB hash function is a well-known hash method
for strings, so I do not see any reasons not to use it.



Update: As of Swift 4.1, the compiler can synthesize 
Equatable and Hashable for types conformance automatically, if all 
members conform to Equatable/Hashable (SE0185). And as of Swift 4.2,
a high-quality hash combiner is built-in into the Swift standard
library (SE-0206).

Therefore there is no need anymore to define your own hashing function,
it suffices to declare the conformance:

struct ScalarString: Hashable, ... {

    private var scalarArray: [UInt32] = []

    // ...
}