comparison modules/sets.tp @ 126:a2d2d8e09291

Merge
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Aug 2013 23:37:17 -0700
parents 6f8d868e8da0 a905e13db753
children
comparison
equal deleted inserted replaced
125:6f8d868e8da0 126:a2d2d8e09291
1 #{ 1 #{
2 hash <- { 2 hash <- {
3 empty <- #{ 3 empty <- #{
4 empty? <- { true } 4 empty? <- { true }
5 } 5 }
6 size <- 0
7 hashdiffs <- #[0]
6 #{ 8 #{
7 buckets <- #[empty empty empty empty] 9 buckets <- #[empty empty empty empty]
8 size <- 0 10 size <- 0
9 contains? <- :object { 11 contains? <- :object {
10 hv <- object hash 12 hv <- object hash
11 13
12 notdone <- true 14 notdone <- true
13 hashes <- #[hv (hv + 1) (hv - 1)] 15
16 basehash <- hv
14 i <- 0 17 i <- 0
15 ret <- false 18 ret <- false
16 while: { if: notdone { i < 3 } } do: { 19 while: { if: notdone { i < (hashdiffs length) } } do: {
17 hv <- hashes get: i 20 hv <- basehash + (hashdiffs get: i)
18 trunc <- hv % (buckets length) 21 trunc <- hv % (buckets length)
19 if: trunc < 0 { trunc <- 0 - trunc } 22 if: trunc < 0 { trunc <- 0 - trunc }
20 bucketval <- (buckets get: trunc) 23 bucketval <- (buckets get: trunc)
21 if: (bucketval empty?) { 24 if: (bucketval empty?) {
22 notdone <- false 25 notdone <- false
40 v <- hv 43 v <- hv
41 eq <- :other { v = other } 44 eq <- :other { v = other }
42 } 45 }
43 } 46 }
44 notdone <- true 47 notdone <- true
45 hashes <- #[hv (hv + 1) (hv - 1)] 48 basehash <- hv
46 i <- 0 49 i <- 0
47 while: { if: notdone { i < 3 } } do: { 50 while: { if: notdone { i < (hashdiffs length) } } do: {
48 hv <- hashes get: i 51 hv <- basehash + (hashdiffs get: i)
49 trunc <- hv % (buckets length) 52 trunc <- hv % (buckets length)
50 if: trunc < 0 { trunc <- 0 - trunc } 53 if: trunc < 0 { trunc <- 0 - trunc }
51 bucketval <- (buckets get: trunc) 54 bucketval <- (buckets get: trunc)
52 if: (bucketval empty?) { 55 if: (bucketval empty?) {
53 size <- size + 1 56 size <- size + 1
59 } 62 }
60 } 63 }
61 i <- i + 1 64 i <- i + 1
62 } 65 }
63 if: notdone { 66 if: notdone {
64 newsize <- (buckets length) * 3 67 newsize <- (buckets length) * 3 + 1
68 lastdiff <- hashdiffs get: ((hashdiffs length) - 1)
69 if: lastdiff <= 0 {
70 hashdiffs append: ((0 - lastdiff) + 1)
71 } else: {
72 hashdiffs append: (0 - lastdiff)
73 }
65 newbucks <- #[] 74 newbucks <- #[]
66 newbucks resize: newsize 75 newbucks resize: newsize
67 while: { (newbucks length) < newsize } do: { 76 while: { (newbucks length) < newsize } do: {
68 newbucks append: empty 77 newbucks append: empty
69 } 78 }