summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorLolo Iccl <oxisccl@gmail.com>2018-05-05 06:20:44 +0900
committerAndreas Rumpf <rumpf_a@web.de>2018-05-09 17:41:41 +0200
commitee8313da3ff19d9340285c7177db84e1c62fc108 (patch)
tree2cf3199ee548d10069016b8873ccf2d14d55748c /lib
parent80f17f94053dbf79e851ac2c90dd6e108c178a61 (diff)
downloadNim-ee8313da3ff19d9340285c7177db84e1c62fc108.tar.gz
Modify previous commit
Modify previous commit to use data[h].hcode in
proc hash for HashSet and for OrderedSet.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/collections/sets.nim12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim
index 0019f8e3a..900f281e9 100644
--- a/lib/pure/collections/sets.nim
+++ b/lib/pure/collections/sets.nim
@@ -120,9 +120,11 @@ iterator items*[A](s: HashSet[A]): A =
   for h in 0..high(s.data):
     if isFilled(s.data[h].hcode): yield s.data[h].key
 
-proc hash*[A](x: HashSet[A]): Hash =
+proc hash*[A](s: HashSet[A]): Hash =
   ## hashing of HashSet
-  for item in x: result = result !& hash(item)
+  assert s.isValid, "The set needs to be initialized."
+  for h in 0..high(s.data):
+    result = result !& s.data[h].hcode
   result = !$result
 
 const
@@ -695,9 +697,11 @@ iterator items*[A](s: OrderedSet[A]): A =
   forAllOrderedPairs:
     yield s.data[h].key
 
-proc hash*[A](x: OrderedSet[A]): Hash =
+proc hash*[A](s: OrderedSet[A]): Hash =
   ## hashing of OrderedSet
-  for item in x: result = result !& hash(item)
+  assert s.isValid, "The set needs to be initialized."
+  forAllOrderedPairs:
+    result = result !& s.data[h].hcode
   result = !$result
 
 iterator pairs*[A](s: OrderedSet[A]): tuple[a: int, b: A] =
71 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292