Security with data structures

Make a Hash

Article from Issue 148/2013
Author(s):

What do all programs have in common? They store data at some point, usually in arrays – everything from command-line options to the input and output. But how is data actually stored by the program? Kurt explains.

Many data types and structures exist – from simple strings and integers to multi-dimensional arrays. One of the most common and useful types is the simple growable array that can contain an arbitrary number of elements. You can basically put data in, look it up, and remove it as needed; this structure is also referred to as a one-dimensional array. Often, you can also insert an array as a data element into an existing array, giving you a multi-dimensional array that lets you do things like create a "customer" array with a number of elements containing a customer name, phone number, and so forth.

About Arrays

Arrays typically have three major operations: insertion (adding elements), lookups (reading a value), and removing elements. There are a number of ways to structure the data in memory, and various strategies can be used to optimize operations on the array. A simple linked list, for example, makes it easy to add an element to the beginning or end of an array but expensive to insert an item into the middle, because it must search the array for the appropriate location. In general, most programming languages that provide well-formed data array structures, such as Perl, Python, Ruby, and so forth, do a pretty good job.

The most common strategy is to create a key based on the data (essentially a hash value), the array is then ordered by these keys. A significant benefit here is that the keys will (usually) have a random and relatively uniform distribution (e.g., 01, 23, 45, 67, 89). This approach is helpful when using things like binary trees, which benefit from having balanced key distribution. This is also referred to as a hash map.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Security Lessons – Hash Maps

    What do all programs have in common? They store data at some point, usually in arrays – everything from commandline options to the input and output. But how is data actually stored by the program? Kurt explains.

  • Hash Functions

    Cryptographic hash functions help you protect your passwords, but hashing is only secure if properly understood.

  • Tutorials – Bash Arrays

    Discover the data structures that make your shell scripts really powerful.

  • Security Lessons: Password Storage

    High-performance graphics cards and proper storage can help keep your passwords secure.

  • Memcached

    This practical caching tool can reduce the load on a web database server by as much as 90%.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News