Skip to content

Commit da64820

Browse files
author
Mike Pollard
committed
Replace all hashValue with hash(into…)
1 parent 140722d commit da64820

File tree

5 files changed

+35
-51
lines changed

5 files changed

+35
-51
lines changed

Sources/GraphQL/Error/GraphQLError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ extension GraphQLError : CustomStringConvertible {
9191
}
9292

9393
extension GraphQLError : Hashable {
94-
public var hashValue: Int {
95-
return message.hashValue
94+
public func hash(into hasher: inout Hasher) {
95+
hasher.combine(message)
9696
}
9797

9898
public static func == (lhs: GraphQLError, rhs: GraphQLError) -> Bool {

Sources/GraphQL/Language/AST.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ public final class OperationDefinition {
337337
}
338338

339339
extension OperationDefinition : Hashable {
340-
public var hashValue: Int {
341-
return ObjectIdentifier(self).hashValue
340+
public func hash(into hasher: inout Hasher) {
341+
hasher.combine(ObjectIdentifier(self))
342342
}
343343

344344
public static func == (lhs: OperationDefinition, rhs: OperationDefinition) -> Bool {
@@ -450,8 +450,8 @@ public final class SelectionSet {
450450
}
451451

452452
extension SelectionSet : Hashable {
453-
public var hashValue: Int {
454-
return ObjectIdentifier(self).hashValue
453+
public func hash(into hasher: inout Hasher) {
454+
hasher.combine(ObjectIdentifier(self))
455455
}
456456

457457
public static func == (lhs: SelectionSet, rhs: SelectionSet) -> Bool {
@@ -709,8 +709,8 @@ public final class FragmentDefinition {
709709
}
710710

711711
extension FragmentDefinition : Hashable {
712-
public var hashValue: Int {
713-
return ObjectIdentifier(self).hashValue
712+
public func hash(into hasher: inout Hasher) {
713+
hasher.combine(ObjectIdentifier(self))
714714
}
715715

716716
public static func == (lhs: FragmentDefinition, rhs: FragmentDefinition) -> Bool {

Sources/GraphQL/Map/Map.swift

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -597,38 +597,22 @@ public func == (lhs: Map, rhs: Map) -> Bool {
597597
// MARK: Hashable
598598

599599
extension Map : Hashable {
600-
public var hashValue: Int {
600+
public func hash(into hasher: inout Hasher) {
601601
switch self {
602602
case .null:
603-
return 0
603+
hasher.combine(0)
604604
case .bool(let bool):
605-
return bool.hashValue
605+
hasher.combine(bool)
606606
case .double(let double):
607-
return double.hashValue
607+
hasher.combine(double)
608608
case .int(let int):
609-
return int.hashValue
609+
hasher.combine(int)
610610
case .string(let string):
611-
return string.hashValue
611+
hasher.combine(string)
612612
case .array(let array):
613-
var hash = 5381
614-
615-
for item in array {
616-
hash = ((hash << 5) &+ hash) &+ item.hashValue
617-
}
618-
619-
return hash
613+
hasher.combine(array)
620614
case .dictionary(let dictionary):
621-
var hash = 5381
622-
var keyHash = 5381
623-
var valueHash = 5381
624-
625-
for (key, value) in dictionary {
626-
keyHash = ((keyHash << 5) &+ keyHash) &+ key.hashValue
627-
valueHash = ((valueHash << 5) &+ valueHash) &+ value.hashValue
628-
hash = ((hash << 5) &+ hash) &+ (keyHash ^ valueHash)
629-
}
630-
631-
return hash
615+
hasher.combine(dictionary)
632616
}
633617
}
634618
}

Sources/GraphQL/Type/Definition.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ extension GraphQLScalarType {
228228
}
229229

230230
extension GraphQLScalarType : Hashable {
231-
public var hashValue: Int {
232-
return ObjectIdentifier(self).hashValue
231+
public func hash(into hasher: inout Hasher) {
232+
hasher.combine(ObjectIdentifier(self))
233233
}
234234

235235
public static func == (lhs: GraphQLScalarType, rhs: GraphQLScalarType) -> Bool {
@@ -332,8 +332,8 @@ extension GraphQLObjectType {
332332
}
333333

334334
extension GraphQLObjectType : Hashable {
335-
public var hashValue: Int {
336-
return ObjectIdentifier(self).hashValue
335+
public func hash(into hasher: inout Hasher) {
336+
hasher.combine(ObjectIdentifier(self))
337337
}
338338

339339
public static func == (lhs: GraphQLObjectType, rhs: GraphQLObjectType) -> Bool {
@@ -659,8 +659,8 @@ extension GraphQLInterfaceType {
659659
}
660660

661661
extension GraphQLInterfaceType : Hashable {
662-
public var hashValue: Int {
663-
return ObjectIdentifier(self).hashValue
662+
public func hash(into hasher: inout Hasher) {
663+
hasher.combine(ObjectIdentifier(self))
664664
}
665665

666666
public static func == (lhs: GraphQLInterfaceType, rhs: GraphQLInterfaceType) -> Bool {
@@ -738,8 +738,8 @@ extension GraphQLUnionType {
738738
}
739739

740740
extension GraphQLUnionType : Hashable {
741-
public var hashValue: Int {
742-
return ObjectIdentifier(self).hashValue
741+
public func hash(into hasher: inout Hasher) {
742+
hasher.combine(ObjectIdentifier(self))
743743
}
744744

745745
public static func == (lhs: GraphQLUnionType, rhs: GraphQLUnionType) -> Bool {
@@ -875,8 +875,8 @@ extension GraphQLEnumType {
875875
}
876876

877877
extension GraphQLEnumType : Hashable {
878-
public var hashValue: Int {
879-
return ObjectIdentifier(self).hashValue
878+
public func hash(into hasher: inout Hasher) {
879+
hasher.combine(ObjectIdentifier(self))
880880
}
881881

882882
public static func == (lhs: GraphQLEnumType, rhs: GraphQLEnumType) -> Bool {
@@ -1009,8 +1009,8 @@ extension GraphQLInputObjectType {
10091009
}
10101010

10111011
extension GraphQLInputObjectType : Hashable {
1012-
public var hashValue: Int {
1013-
return ObjectIdentifier(self).hashValue
1012+
public func hash(into hasher: inout Hasher) {
1013+
hasher.combine(ObjectIdentifier(self))
10141014
}
10151015

10161016
public static func == (lhs: GraphQLInputObjectType, rhs: GraphQLInputObjectType) -> Bool {
@@ -1137,8 +1137,8 @@ extension GraphQLList {
11371137
}
11381138

11391139
extension GraphQLList : Hashable {
1140-
public var hashValue: Int {
1141-
return ObjectIdentifier(self).hashValue
1140+
public func hash(into hasher: inout Hasher) {
1141+
hasher.combine(ObjectIdentifier(self))
11421142
}
11431143

11441144
public static func == (lhs: GraphQLList, rhs: GraphQLList) -> Bool {
@@ -1210,8 +1210,8 @@ extension GraphQLNonNull {
12101210
}
12111211

12121212
extension GraphQLNonNull : Hashable {
1213-
public var hashValue: Int {
1214-
return ObjectIdentifier(self).hashValue
1213+
public func hash(into hasher: inout Hasher) {
1214+
hasher.combine(ObjectIdentifier(self))
12151215
}
12161216

12171217
public static func == (lhs: GraphQLNonNull, rhs: GraphQLNonNull) -> Bool {

Sources/GraphQL/Validation/Validate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ enum HasSelectionSet {
7777
}
7878

7979
extension HasSelectionSet : Hashable {
80-
var hashValue: Int {
80+
func hash(into hasher: inout Hasher) {
8181
switch self {
8282
case .operation(let operation):
83-
return operation.hashValue
83+
return hasher.combine(operation.hashValue)
8484
case .fragment(let fragment):
85-
return fragment.hashValue
85+
return hasher.combine(fragment.hashValue)
8686
}
8787
}
8888

0 commit comments

Comments
 (0)