Doubly Linked Lists and the Abstract Data Type
As shown above, there are four pointers in the top-level structure. We concern ourselves here with the current pointer. This pointer is where all the power in the DLL comes from and is used in many of the DLL's functions to determine what to work on.
The next two functions move the current pointer to the head or tail of the list.
DLL_Return DLL_CurrentPointerToHead(List *list); DLL_Return DLL_CurrentPointerToTail(List *list);
Often, incrementing or decrementing the pointer is necessary:
DLL_Return DLL_IncrementCurrentPointer(List *list); DLL_Return DLL_DecrementCurrentPointer(List *list);It is sometimes desirable to store the current pointer, then do something else, and then restore the pointer. We take care of this in the next two functions.
DLL_Return DLL_StoreCurrentPointer(List *list);
DLL_Return DLL_RestoreCurrentPointer(List *list);
There is little use having a linked list if you cannot find what has been stored in it. The following functions let you find your data and specify exactly how that data will be found.
DLL_Return DLL_FindRecord(List *list, Info *record,
Info *match, int (*pFun)(Info *, Info *));
The first argument, as usual, is the pointer to the linked list. The second is a pointer to the returned data. The third is a pointer to the matching criteria, and the last argument is a pointer to the compare function that was previously described in the data modification group. This compare function can be constructed differently, but the idea is the same.
Now life gets a little difficult. The above function needs to know how to look for the data in the linked list. Does it look down from the head pointer, up from the tail pointer, or up or down from the current pointer? My solution to this problem was to use a state table.
There are two more typedef enumerations needed, relating to the state table, one to set the origin of the search and the other to set its direction.
typedef enum
{
DLL_ORIGIN_DEFAULT, /* Use current origin
* setting */
DLL_HEAD, /* Set origin to head pointer */
DLL_CURRENT, /* Set origin to current pointer */
DLL_TAIL /* Set origin to tail pointer */
} DLL_SrchOrigin;
typedef enum
{
DLL_DIRECTION_DEFAULT, /* Use current direction
* setting */
DLL_DOWN, /* Set direction to down */
DLL_UP, /* Set direction to up */
} DLL_SrchDir;
The state table defaults at initialization to DLL_HEAD and DLL_DOWN. The DLL_FindRecord function uses these values if not changed. To change the operation of this function, use the next two functions shown. If no change is desired in either of these two functions, use DLL_ORIGIN_DEFAULT or DLL_DIRECTION_DEFAULT. The first function sets the table to new values:
DLL_Return DLL_SetSearchModes(List *list,
DLL_SrchOrigin origin, DLL_SrchDir dir);
The second function returns a pointer of a copy of the state table
to the following structure:
typedef struct search_modes
{
DLL_SrchOrigin search_origin;
DLL_SrchDir search_dir;
} DLL_SearchModes;
The purpose of this function is to check how a succeeding search
will be conducted by interrogating the state table.
DLL_Return DLL_GetSearchModes(List *list);Last in this group are three functions that return data relative to the location of the current pointer. They are not affected by the state table.
DLL_Return DLL_GetCurrentRecord(List *list,
Info *record);
DLL_Return DLL_GetPriorRecord(List *list,
Info *record);
DLL_Return DLL_GetNextRecord(List *list,
Info *record);
Generally, input and output functions would not be considered a part of a linked list implementation; however, they do make life a bit easier when using ADTs. Without these functions one would have to set the current pointer to the head or tail of the list and then make repeated calls to one of the DLL_Get functions mentioned above. If sorting during this process were needed, the task would be even more tedious.
Writing to or reading from a disk tends to be very platform specific. I have striven to make the next two functions as generic as possible; they open files in binary mode and write or read the Info structure from beginning to end. Depending on how you enter data in the Info structure will determine if there will be any endian problems.
To save a list, determine the full path to the file, then pass its pointer to the next function. There are no sorting options with this function, because the list is presumably sorted in memory and will be saved in that order.
DLL_Return DLL_SaveList(List *list,
const char *path);
When loading a file from disk, you have the option of sorting the list as it comes into memory. Passing a NULL loads the file as it exists on the disk and loads it faster than if the list is sorted.
DLL_Return DLL_LoadList(List *list, const char *path, int (*pFun)(Info *, Info *));
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




17 min 47 sec ago
7 hours 11 min ago
7 hours 28 min ago
9 hours 19 min ago
15 hours 11 min ago
19 hours 42 min ago
19 hours 43 min ago
21 hours 43 min ago
1 day 6 hours ago
1 day 7 hours ago