affiliate marketing
Showing posts with label data structure. Show all posts
Showing posts with label data structure. Show all posts

Monday, 12 December 2011

4. Abstract Data Type


4.1. Alternative Implementations Of Fractions
Returning to our example of the fraction data type, how might we actually implement this datatype in C?
Implementation 1
typedef struct { int numerator,denominator; } fraction;

main()
{
  fraction f;
  f.numerator   = 1;
  f.denominator = 2;
  ...
}
Implementation 2
#define numerator   0
#define denominator 1
typedef int fraction[2];

main()
{
  fraction f;
  f[numerator]   = 1;
  f[denominator] = 2;
  ...
}
These are just 2 of many different possibilities. Obviously, these differences are in some sense extremely trivial - they do not affect the domain of values or meaning of the operations of fractions.

HASH FUNCTION


Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value. It is also used in many encryption algorithms.

Hash Function:
A Hash Function is a Unary Function that is used by Hashed Associative Containers: it maps its argument to a result of type size_t. A Hash Function must be deterministic and stateless. That is, the return value must depend only on the argument, and equal arguments must yield equal results.
Hash functions are mostly used in hash tables, to quickly locate a data record (for example, a dictionarydefinition) given its search key (the headword). Specifically, the hash function is used to map the search key to the index of a slot in the table where the corresponding record is supposedly stored.
Division Method: