Professional Documents
Culture Documents
Ng Eu Jinn 1071112650 Click to edit Master subtitle style Tan Chin Tong 1081106274 Ng Cong Jie 1071117296 Mostafa Abedi 1091108989 Tan Joanne 1071115484
5/4/12
Bit 8 16 32
Name
Decimal Digits 3 5 10
Twos complement
5/4/12
Complex
ordered pairs of floating point values
Decimal
store fixed number of decimal digits with the
efficiently)
stored in the smallest efficiently addressable
cell of memory
(1 byte)
Pattern matching
supported directly in the language or provided
library
5/4/12
maximum
5/4/12
Sub range
contiguous subsequence of an ordinal type
5/4/12
5/4/12
Perl
Sign @ for array : e.g. @list Sign e.g.$list[1] +ve $ for scalars : 2 0 1 3 4 subscript subscript Negative Arrays 0 1 2 3 4 Element -ve -5 -4 -3 -2 -1
5/4/12
comparisons
5/4/12
6.5.7 Slices
Python:
mat 0 1 2 0 1 4 7 1 2 5 8 2 3 6 9
vect 0 1 2 3 or 0 2 6 vector [0 4: 8 : 2] 8
10->12 ,6, [2 14
16 17 10, 14]
5/4/12
Column Major Order Order 6 2 5 34 7 34 7 6 2 5 1 3 86 2 5 1 3 8 1 3 8 3, 4, 7, 6, 2, 5, 3 46, 1, 4, 2, 3, a 1 2 3, 5 6 7 8 9 1, 3,1 8 7, 5, 8 location(a [i, j]) = 2 adress of a[1, 1] + (( 3 ((# of rows above ith row) 4 * (size of row)) + 5 X (# of columns left of column)) location (a Adress jth 6 9 5 5/4/12 4 ) x [5, 6]) = a[1, 1] + ( ( x + element
3 4 Row Major 7
Associative Arrays
An unordered collection of data elements
that are indexed by an equal number of values called keys. value) Value Key
Eujinn 70 Marry 99 Joanne 55 Johnny 41
=> Dataset[Eujinn] = 70; => Dataset[Marry] = 99; => Dataset[Joanne] = 55; => Dataset[Johnny] = 41; 5/4/12
hash functions
Key John
Hashe 61409aa1fd d Key 47d4a Hashed Value Key 61409aa 70 1f Perl => Key must be string 8a31409 99 PHP => Key either integer or string aa.. Ruby => Key can be any object af115391 55 5/4/12 a.. PHP => Both array and associative array HASH FUNCTIO N
Delete
delete $salaries{Gary}; salaries.erase(Gary);
Exists
If(exists $salaries{Shelly}) If( salaries.find(Shelly))
//In C++
Record Type
Is used to group collection of data with
struct Employee {
string name; int age; float salary;
};
5/4/12
memory locations
off set
Inde TypeSize x 0 int 32 Differ bit ent int 32 Size 1 bit Arr ay 5/4/12 32 2 int
Sa me Siz e
OUTPUT-RECORD
5/4/12
Union Type
A type whose variable may store different
Specifying Union
5/4/12
issue
2 ways of implementations
Free Union
Programmers are allowed complete freedom from
Discriminated Union
Type indicator(tag) is used for type checking Use in ALGOL 68 , ADA
5/4/12
11101 00000 00000 00000 000 011 000 000 C[0] => 232 C[1] = 3 a => 100010
(11111010002)
5/4/12
pointer or Dangling reference: occurs when a pointer stores the address of an already deallocated heap-dynamic variable. causing this.
Explicit deallocation is the major reason Location can be reallocated to a new heap-
dynamic variable.
5/4/12
Solution: Tombstone
Tombstones:
Every
heap-dynamic variable includes an extra cell ( tombstone ) that is itself a pointer to the heap dynamic variable. -> tombstone -> heap-dynamic is variable
Pointer When
Disadvantages :
Costly in memory and time.
5/4/12
Solution: Lock-and-Keys
Pointers instead of only being an address,
also have a key and are made into a pair. (key, address) containing a lock.
Heap-dynamic variables also have a header When allocated, the key(in pointer) and the
lock( in the variable) are set the same. (key=lock) pointer, access is granted only if the lock and key match. Otherwise its an error.
5/4/12
that
is
not
This
5/4/12
Pointers
In Ada:
are called access. Diminishes the dangling pointers problem :
Garbage collection (not supported in all compilers)
not eliminated.
variable problem is
in C and C++:
Pointers are infinitely flexible, must be used
with care.
Reference Type
a pointer refers to an address, a reference
refers to an object.
reference implicitly.
is
always
dereferenced
no longer useful.
Two methods:
Reference counters ( eager approach ) Mark-sweep ( lazy approach )
5/4/12
Reference counters
Every cell has a counter. It counts the
connected reclaimed.
circularly
are
never
when they are found to be 5/4/12 garbage. the reclaimation is done throughout the
Mark-Sweep
Allocates cell and disconnect them, without
reclaiming. (lets the garbage to build up) mark-sweep process reclaims garbage floating around. all
the
Mark-sweep 3 phases:
Set phase Mark phase Sweep phase
5/4/12
Mark-Sweep
The
problem enough.
Costly in time.
is
that
it
isnt
frequent
Incremental mark-sweep:
Occurs more frequently, before the available
space is finished. The time for the process decrease, reducing the delay.
Another solution:
to perform mark-sweep process on specific
5/4/12 parts of the memory rather than the whole
sweep:
chain?
maintaining a list of available space.
5/4/12
Type Checking
Process to verify that the operands of an
A compatible type is
automatically converted by the compilergenerated code to a legal type (also known as coercion).
5/4/12
Example of a compatible type: int x, y, z; x = y + z; Example of coercion in Java where the the int variable is coerced to float: int x; float y, z; y = x + z;
5/4/12
Type Error
Happens when an operator is applied to an
5/4/12
5/4/12
Strong Typing
A strongly typed programming language
has severe restrictions that prevents the compilation of code with data that is used in an invalid way.
Type errors are always detected. Requires that the types of all operands
Example:
weakened by coercion as it results in the loss of error detection. - Coercion Reliability - Coercion Reliability
Reliability of a language
5/4/12
variable of one type to refer to a value of a different type, without the system being able to check the type of the value when one of the Equivalenced variables is referenced or assigned.
C and C++ both include union types which are
5/4/12
Ada, Java, C#
Nearly strongly typed. Ada allows programmers to breach type-
5/4/12
Type Equivalence
Strict form of type compatibility. No coercion. 2 ways to define type equivalence
Name type equivalence Structure type equivalence
5/4/12
the same declaration or in declarations that use the same type name.
Easy to implement. Compare only 2 type names. All types must have names. Restrictive. For example, a variables type with subrange of integers
5/4/12
More flexible compared to name type Difficult to implement. Entire structures of 2 types have to be
compared.
5/4/12
Derived Type
Subtype
parent type.
Has identical
Type Theory
2 branches in computer science
Practical Abstract
Practical branch
Concerned with data types in commercial
programming languages.
Abstract branch
Concerned with typed lambda calculus, an
Data Type
Defines a set of values. Defines a collection of operations on those
values.
Elements are often ordered. Set operations can be used on data types
5/4/12
Thank You!
5/4/12