Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- note
- description: "Objects that represent ADT MAP:KEY x VALUE."
- author: "Przemyslaw Pawluk"
- date: "2013 May 9"
- version: 1.0
- class
- MY_MAP[K,V]
- create
- make
- feature --Representation
- list:LINKED_LIST[ITEM[K,V]]
- count: INTEGER -- counter
- feature {ANY}
- make
- --creates all required variables
- do
- --??? {LINK_LIST[ITEM]}
- create list.make
- count:=0;
- ensure
- --??
- count = 0
- list.is_empty
- end
- put(key: K; value: V)
- require
- -- key /= void
- -- value /= void -- ensure the value is not void because equals reqires no void values
- local
- i: INTEGER
- --duplicate_key: BOOLEAN
- item: ITEM[K,V]
- do
- --io.put_string ("k" + key.out + "," + value.out)
- create item.make (key,value)
- --duplicate_key = true
- from
- i := 1
- until
- i >= list.count
- loop
- --list.go_i_th (i: INTEGER_32)
- if list.i_th (i).getkey.is_deep_equal (key)
- then
- list.remove
- end
- -- io.put_string ("k" + key.out + "," + value.out)
- i := i + 1
- end
- list.extend (item)
- --???
- ensure
- --???
- -- list.item.getvalue /= void
- end;
- get(key:K):V
- require
- Key /= void
- local
- i : INTEGER
- do
- from
- i := 1
- until
- i >= list.count
- loop
- --list.go_i_th (i: INTEGER_32)
- if list.i_th (i).getkey.is_deep_equal (key)
- then
- result := list.item_for_iteration.getvalue
- end
- i := i + 1
- end
- ensure
- list.item_for_iteration.getvalue /= void
- --Result/=void
- end
- remove(key:K)
- local
- i:INTEGER
- do
- from
- i := 1
- until
- i >= list.count
- loop
- --list.go_i_th (i: INTEGER_32)
- if list.i_th (i).getkey.is_deep_equal (key)
- then
- list.remove
- end
- i := i + 1
- end
- --???
- ensure
- --???
- end
- has(key:K; val:V):BOOLEAN
- require
- --key /= void
- local
- i:INTEGER
- return : BOOLEAN
- do
- return := false
- from
- i := 1
- until
- i >= list.count
- loop
- if list.i_th (i).getkey.is_deep_equal (key) and list.i_th (i).getvalue.is_deep_equal(val)
- then
- return := true
- end
- i := i + 1
- end
- --???
- result := return
- ensure
- --???
- end
- key_set:SET[K]
- -- returns a set of key values from the map
- local
- set: SET[K]
- i:INTEGER
- do
- --create
- from
- i := 1
- until
- i >= list.count
- loop
- list.go_i_th (i)
- set.extend (list.item_for_iteration.getkey)
- i := i + 1
- end
- result := set
- --???
- ensure
- --???
- end
- value_set:SET[V]
- -- returns a set of values from the map
- local
- i:INTEGER
- set: SET[V]
- do
- --create set.make
- from
- i := 1
- until
- i >= list.count
- loop
- list.go_i_th (i)
- set.put (list.item_for_iteration.getvalue)
- i := i + 1
- end
- result := set
- --???
- ensure
- --???
- end
- feature --Quantifiers
- exist(key:K; val:V):BOOLEAN
- --checks if given key/value combination exist in the map
- do
- --???
- ensure
- --???
- end
- exist1(key:K; val:V):BOOLEAN
- --checks if there is only one pair with given key/value combination
- do
- --???
- ensure
- --???
- end
- has1(key:K):BOOLEAN
- --checks if there is only one key with given value
- do
- --???
- ensure
- --???
- end
- invariant
- count: count>=0
- --???
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement