my_digital_garden/4a1s/MFES/PL - Aula 7.md

57 lines
1.1 KiB
Markdown
Raw Normal View History

2023-11-06 12:25:52 +00:00
https://alloy.readthedocs.io/en/latest/language/signatures.html#relations
2023-11-06 12:15:52 +00:00
>[!note]
>Node.prox' = Node.prox
!=
all n:Node | n.prox' = n.prox
=
prox' = prox
2023-11-06 12:45:52 +00:00
>[!note]
>some b: Bucket | ...
2023-11-06 12:25:52 +00:00
```c
// Recall the hash table Alloy model,
// now with mutable lists inside the buckets.
sig Bucket {
var head : lone Node
}
sig Node {
key : one Key,
var prox : lone Node
}
sig Key {
hash : one Hash
}
sig Hash {}
// Specify the operation of inserting a node
// in the hash table. The node should be
// inserted at the head of a bucket.
// If the operation only works well when the
// hash of the new node does not exist in the
// table you get Two points. If it always
// works well you get Five points. Use the
// respective commands to check how many
// points you have.
2023-11-06 23:08:39 +00:00
2023-11-06 12:25:52 +00:00
pred insert[n : Node] {
2023-11-06 23:08:39 +00:00
//if hash empty -> node to head of bucket
n.key.hash not in Hash implies
(
lone b:Bucket | b.head = node implies b.head' = n
)
//if hash empty -> bucket of desired hash, add to next
n.key.hash in Hash implies
(
lone b: Bucket | b.head.key.hash = n.key.hash | b.head.*prox =
)
2023-11-06 12:25:52 +00:00
}
2023-11-06 23:08:39 +00:00
2023-11-06 12:25:52 +00:00
```