160 likes | 338 Views
Data Design. SIM5104. Principles of data design. Abstract objects of the specification have to be represented by data structures Two modes of data design: Direct Implementer chooses data structures of the targeted programming languages Indirect
E N D
Data Design SIM5104
Principles of data design • Abstract objects of the specification have to be represented by data structures • Two modes of data design: • Direct • Implementer chooses data structures of the targeted programming languages • Indirect • Implementer chooses abstract data types such as files, trees etc.
Abstract view : user’s view • example Test operation Enquire operation Leave operation Enrolled set Tested set Enrolled operation
Concrete view: implementer’s view array tctr ectr is enrolled counter tctr is test counter ectr
Concrete state data Class enrolled, tested : ℙ Student #enrolled ≤ size tested ⊆ enrolled
Concrete state data DClass sarray : (1..size) → Student ectr : 0..size tctr : 0..size tctr ≤ ectr ∀i, j : 1..ectr | i ≠ j • sarray i ≠ sarray j
Forward simulation • To bring together the abstract state and the concrete state Dsim Class DClass enrolled = {i: 1..ectr • sarray i} tested = {i:1..tctr • sarray i}
Concrete Initial State DInit DClass’ ectr’ = ∅
Enrolling a student: abstract EnrolOk ∆Class s? : Student r! : Response s? ∉ enrolled #enrolled < size enrolled’ = enrolled ∪ {s?} tested’ = tested r! = success
Enrolling a student: concrete DEnrolOk ∆DClass s? : Student r! : Response ∀i : 1..ectr • sarray i ≠ s? ectr < size tctr’ = tctr ectr’ = ectr + 1 sarray’ = sarray ⊕ {ectr’ ↦ s?} r! = success
Corresponding predicates Abstract concrete ∀i : 1..ectr • sarray i ≠ s? ectr < size ectr’ = ectr + 1 tctr’ = tctr sarray’ = sarray ⊕ {ectr’ ↦ s?} r! = success s? ∉ enrolled #enrolled < size enrolled’ = enrolled ∪ {s?} tested’ = tested r! = success
Other related schemas DNoRoom ΞDClass r! : Response ectr = size r! = noroom DAlreadyEnrolled ΞDClass s?: Student r! : Response ∃i: 1.. ectr • sarray i = s? r! = alreadyenrolled DEnrol ≙ DEnrolOk ⋁ DNoRoom ⋁ DAlreadyEnrolled
Using Linked Lists next data next data next data head next data [Pointer, Data] Given set for pointer and the kind of data stored In the blocks in the linked list | nil_pointer : Pointer A pointer does not point at anything Block next : Pointer data : Data Type of blocks in the list
Linking of blocks : Queue Queue head : Pointer block_at : Pointer ↛ Block pointers : seq Pointer nil_pointer ∉ dom block_at ran pointers = dom block_at #pointers = #ran pointers pointers = < > ⇔ head = nil_pointer ( pointers ≠ < > ⇒ ( head pointers = head ⋀ (block_at (last pointers)).next = nil_pointer ⋀ (∀i: 1..(#pointers – 1) • (block_at(pointers i)).next = pointers(i + 1)))) Starting pointer Relation between pointers and the block they address Sequence of pointer to chain block together
Add to head AddToHead ∆Queue Block new_pointer? : Pointer data? : Data new_pointer? ∉ dom block_at data = data? pointers’ = <new_pointer> ^ pointers block_at’ = block_at ⊕ {new_pointer? ↦ θBlock}