@@ -52,7 +52,7 @@ public struct HashSlot: Hashable, Sendable {
5252 /// The minimum valid hash slot value (0).
5353 public static let min = HashSlot ( . hashSlotMin)
5454
55- /// The total number of hash slots in a Valkey cluster (16,384).
55+ /// The total number of hash slots allowed in a Valkey cluster (16,384).
5656 public static let count : Int = 16384
5757
5858 private var _raw : UInt16
@@ -69,23 +69,34 @@ extension HashSlot: Comparable {
6969}
7070
7171extension HashSlot : RawRepresentable {
72+ /// The type that represents the raw value of a hash slot.
7273 public typealias RawValue = UInt16
7374
75+ /// Creates a hash slot based on the raw value you provide for valid hash slot values.
76+ /// - Parameter rawValue: The raw value of the hash slot.
7477 public init ? ( rawValue: UInt16 ) {
7578 guard rawValue <= HashSlot . max. rawValue else { return nil }
7679 self . _raw = rawValue
7780 }
7881
82+ /// Creates a hash slot based on the raw value you provide for valid hash slot values, or returns nil if the raw value isn't within the valid range.
83+ /// - Parameter rawValue: The raw value of the hash slot.
84+ ///
85+ /// The raw value must be within ``HashSlot/min`` (`0`) to ``HashSlot/max`` (`16383`) to initialize.
86+ /// If you pass in an Int value beyond that range, the initializer returns `nil`.
7987 public init ? ( rawValue: Int ) {
8088 guard HashSlot . min. rawValue <= rawValue, rawValue <= HashSlot . max. rawValue else { return nil }
8189 self . _raw = UInt16 ( rawValue)
8290 }
8391
92+ /// Creates a hash slot based on the raw value you provide for valid hash slot values.
93+ /// - Parameter rawValue: The raw value of the hash slot.
8494 public init ? ( rawValue: Int64 ) {
8595 guard HashSlot . min. rawValue <= rawValue, rawValue <= HashSlot . max. rawValue else { return nil }
8696 self . _raw = UInt16 ( rawValue)
8797 }
8898
99+ /// The raw value of a hash slot.
89100 public var rawValue : UInt16 { self . _raw }
90101}
91102
@@ -130,8 +141,8 @@ extension HashSlot {
130141 /// The algorithm calculates the CRC16 of either the entire key or a specific part of the key
131142 /// enclosed in curly braces (`{...}`), then performs modulo 16384 to get the slot number.
132143 ///
133- /// - Parameter key: The key used in a Valkey command
134- /// - Returns: A HashSlot representing where this key would be stored in the cluster
144+ /// - Parameter key: The key used in a Valkey command.
145+ /// - Returns: A HashSlot representing where this key would be stored in the cluster.
135146 @inlinable
136147 public init ( key: some BidirectionalCollection < UInt8 > ) {
137148 // Banging is safe because the modulo ensures we are in range
@@ -140,8 +151,8 @@ extension HashSlot {
140151
141152 /// Creates a hash slot for a Valkey key.
142153 ///
143- /// - Parameter key: The Valkey key for which to calculate the hash slot
144- /// - Returns: A HashSlot representing where this key would be stored in the cluster
154+ /// - Parameter key: The Valkey key for which to calculate the hash slot.
155+ /// - Returns: A HashSlot instance that represents where this key would be stored in the cluster.
145156 @inlinable
146157 public init ( key: ValkeyKey ) {
147158 switch key. _storage {
@@ -157,12 +168,12 @@ extension HashSlot {
157168 /// Computes the portion of the key that should be used for hash slot calculation.
158169 ///
159170 /// Follows the Valkey hash tag specification:
160- /// - If the key contains a pattern like "{...}", only the content between the braces is used for hashing
161- /// - If the pattern is empty "{}", or doesn't exist, the entire key is used
162- /// - Only the first occurrence of "{...}" is considered
171+ /// - If the key contains a pattern like "{...}", only the content between the braces is used for hashing.
172+ /// - If the pattern is empty "{}", or doesn't exist, the entire key is used.
173+ /// - Only the first occurrence of "{...}" is considered.
163174 ///
164- /// - Parameter keyUTF8View: The UTF8 view of key for your operation
165- /// - Returns: A substring UTF8 view that will be used in the CRC16 computation
175+ /// - Parameter keyUTF8View: The UTF-8 view of key for your operation.
176+ /// - Returns: A UTF-8 sequence to use in the CRC16 computation to compute a hash slot.
166177 @inlinable
167178 package static func hashTag< Bytes: BidirectionalCollection < UInt8 > > ( forKey keyUTF8View: Bytes ) -> Bytes . SubSequence {
168179 var firstOpenCurly : Bytes . Index ?
@@ -278,8 +289,8 @@ extension HashSlot {
278289 ///
279290 /// This is the specific CRC16 implementation used by Valkey/Redis for hash slot calculation.
280291 ///
281- /// - Parameter bytes: A sequence of bytes to compute the CRC16 value for
282- /// - Returns: The computed CRC16 value
292+ /// - Parameter bytes: A sequence of bytes used to compute the CRC16 value.
293+ /// - Returns: The computed CRC16 value.
283294 @inlinable
284295 package static func crc16< Bytes: Sequence > ( _ bytes: Bytes ) -> UInt16 where Bytes. Element == UInt8 {
285296 var crc : UInt16 = 0
0 commit comments