160 likes | 301 Views
Oct 25. Group_ID rule Multiple Read-ahead Backtracking. Group-ID Rule. We frequently wish to process groups in a file sorted by group.
E N D
Oct 25 Group_ID rule Multiple Read-ahead Backtracking
Group-ID Rule We frequently wish to process groups in a file sorted by group. Problem statement: Produce a Census report that reports the number of males and females in each household and summarizes the number of households, males and females and average household size as shown below: Household Id# yyyyy #Females xxxxxx #Males xxxxxx Household Id# yyyyy #Females xxxxxx #Males xxxxxx … Household Id# yyyyy #Females xxxxxx #Males xxxxx Totals: # hhlds: yyyyyy # F: xxxxxx # M: xxxxxx ave. hhld size: x.x The input file is a text file with each record (line) containing: Household id 0-3 Person id 4-6 Gender code 7 (‘0’= female, ‘1’= male)
JSP • System diagram • Data structures for: • input - censusFile.jsp • output - censusReport.jsp • Composite data model showing correspondences • Basic Program Structure – censusBasicStr2.jsp • List and allocate operations • Produce elaborated program structure - censusElabStr.jsp • Generate structure text or code • Structure text • Java code
Group ID Rule • Group-id Rule: “If a structure contains a component that is a group of records all having the same value of a (usually sorted) identifier, then there must be an operation that stores the value of the identifier. This operation should be allocated once per group, at the beginning of the group.” • Design focuses on: • a static not a dynamic view of the problem; • data structures (objects), not on dynamic flow of control
Multiple Read-Ahead • Problem: • Write a program to remove all comments from a C program. A comment in C begins with the characters, /*, and ends with the characters, */. Take note of the fact that C allows strings, any characters enclosed by double-quotes ("), as well as constants, which are enclosed in single quotes. • Solution • Data structure • In order to recognize a "C" comment, we must read two consecutive characters prior to selection (static not dynamic view) • Comment Structure • Multiple read-ahead rule • C Program
Bottom-up Design • machine has elementary data types and elementary operations • we may decide that we need data types and operations at a more abstract level Example: We create matrix data structure with operations matadd, matsub, matmult and matdiv, together with matrix constants, matzero and matident to represent the zero and identity matrices. • we have extended our elementary operations by bottom-up design
Generalized vs. Generalized Components • In JSP we build a hierarchic tree structure • Each component depends on one and only one component higher up in the hierarchy. • No generalized components. A change to P2 will have no effect on any other component because each component has structural integrity.
Generalized Components • PC depends only on P2, but PA depends on both P1 and P, while PB depends on P1, P2 and P3. What part of component PB will need to be changed if component P1 is changed? Will this change affect the way PB works as a component of P3?
Generalized Components • In some sense we have optimized since this design has only seven components, whereas our original had eight. • Our components are generalized. We may have saved valuable storage space. • But in the process, we have lost design integrity, and increased the burden of future maintenance.
Bottom-up Versus Generalized Design • We can design new, more general elementary operations using bottom-up design to transform our programming environment. • Creating generalized components is an optimization technique; optimization should only be attempted after a correct design has been derived.