File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 krun -d patterns/tree_string --smt_prelude $(K_Z3 ) /string.smt2 --prove bst/string_find_spec.k bst/find.js
2222 krun -d patterns/tree_string --smt_prelude $(K_Z3 ) /string.smt2 --prove bst/string_insert_spec.k bst/insert.js
2323 krun -d patterns/tree_string --smt_prelude $(K_Z3 ) /string.smt2 --prove bst/string_delete_spec.k bst/delete.js
24+ @echo " BST OOP String"
25+ krun -d patterns/tree_string --smt_prelude $(K_Z3 ) /string.smt2 --prove bst-oop/bst_find_spec.k bst-oop/bst.js
26+ krun -d patterns/tree_string --smt_prelude $(K_Z3 ) /string.smt2 --prove bst-oop/bst_insert_spec.k bst-oop/bst.js
2427 @echo " BST Float"
2528 krun -d patterns/tree_float --smt_prelude $(K_Z3 ) /float.smt2 --prove bst/float_find_spec.k bst/find.js
2629 krun -d patterns/tree_float --smt_prelude $(K_Z3 ) /float.smt2 --prove bst/float_insert_spec.k bst/insert.js
Original file line number Diff line number Diff line change 1+ // Binary Search Tree
2+
3+ BST = function ( ) {
4+ this . root = null ;
5+ } ;
6+
7+ BST . prototype . insert = function ( v ) {
8+ if ( this . root == null ) {
9+ this . root = new BST . Node ( v ) ;
10+ } else {
11+ this . root . insert ( v ) ;
12+ }
13+ } ;
14+
15+ BST . prototype . find = function ( v ) {
16+ if ( this . root == null ) {
17+ return false ;
18+ } else {
19+ return this . root . find ( v ) ;
20+ }
21+ } ;
22+
23+ // Binary Search Tree Node
24+
25+ BST . Node = function ( v ) {
26+ this . value = v ;
27+ this . left = null ;
28+ this . right = null ;
29+ } ;
30+
31+ BST . Node . prototype . insert = function ( v ) {
32+ if ( v < this . value ) {
33+ if ( this . left == null ) {
34+ this . left = new BST . Node ( v ) ;
35+ } else {
36+ this . left . insert ( v ) ;
37+ }
38+ } else if ( v > this . value ) {
39+ if ( this . right == null ) {
40+ this . right = new BST . Node ( v ) ;
41+ } else {
42+ this . right . insert ( v ) ;
43+ }
44+ }
45+ } ;
46+
47+ BST . Node . prototype . find = function ( v ) {
48+ if ( v < this . value ) {
49+ if ( this . left == null ) {
50+ return false ;
51+ } else {
52+ return this . left . find ( v ) ;
53+ }
54+ } else if ( v > this . value ) {
55+ if ( this . right == null ) {
56+ return false ;
57+ } else {
58+ return this . right . find ( v ) ;
59+ }
60+ } else {
61+ return true ;
62+ }
63+ } ;
64+
65+
66+
67+
68+
69+
70+ // function Main() {
71+ // var t = new BST();
72+ // t.insert(2);
73+ // t.insert(1);
74+ // t.insert(3);
75+ // console.log(t);
76+ // console.log(t.find(1));
77+ // console.log(t.find(2));
78+ // console.log(t.find(3));
79+ // console.log(t.find(4));
80+ // }
81+ // Main();
Original file line number Diff line number Diff line change 1+ require "../../js.k"
2+
3+ module BST- SPEC
4+
5+ imports JS
6+
7+ rule
8+ <envs >
9+ ...
10+ ENVS:Bag
11+ (.Bag => ? _:Bag)
12+ ...
13+ </envs >
14+ <objs >
15+ ...
16+ OBJS:Bag
17+ string_tree(O)(T:StringTree)(@o(8 ))
18+ (.Bag => ? _:Bag)
19+ ...
20+ </objs >
21+ <k >
22+ Call(@o(11 ), O:Oid, @Cons(V:String , @Nil))
23+ =>
24+ V inStringSet string_tree_keys(T)
25+ ...
26+ </k >
27+ requires string_bst(T)
28+
29+ // @o(8) : BST.Node.prototype
30+ // @o(11) : BST.Node.prototype.find
31+
32+ endmodule
Original file line number Diff line number Diff line change 1+ require "../../js.k"
2+
3+ module BST-SPEC
4+
5+ imports JS
6+
7+ rule
8+ <envs>
9+ ...
10+ ENVS:Bag
11+ (.Bag => ?_:Bag)
12+ ...
13+ </envs>
14+ <objs>
15+ ...
16+ OBJS:Bag
17+ (
18+ string_tree(O1)(T1:StringTree)(@o(8 ))
19+ =>
20+ string_tree(O1)(?T2:StringTree)(@o(8 ))
21+ ?_:Bag
22+ )
23+ ...
24+ </objs>
25+ <k>
26+ Call(@o(9 ), O1:Oid, @Cons(V:String, @Nil))
27+ =>
28+ Undefined
29+ ...
30+ </k>
31+ requires string_bst(T1)
32+ ensures string_bst(?T2) andBool string_tree_keys(?T2) ==K { V } U string_tree_keys(T1)
33+
34+ // @o(8 ) : BST.Node.prototype
35+ // @o(9 ) : BST.Node.prototype.insert
36+
37+ endmodule
You can’t perform that action at this time.
0 commit comments