-
Notifications
You must be signed in to change notification settings - Fork 0
/
Intro.html
50 lines (50 loc) · 16.9 KB
/
Intro.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><!--This file was converted to xhtml by LibreOffice - see http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/xslt for the code.--><head profile="http://dublincore.org/documents/dcmi-terms/"><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/><title xml:lang="en-US">Introduction to imamLL</title><meta name="DCTERMS.title" content="" xml:lang="en-US"/><meta name="DCTERMS.language" content="en-US" scheme="DCTERMS.RFC4646"/><meta name="DCTERMS.source" content="http://xml.openoffice.org/odf2xhtml"/><meta name="DCTERMS.issued" content="2015-07-01T16:15:47.385259872" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.modified" content="2015-07-05T01:02:49.823962097" scheme="DCTERMS.W3CDTF"/><meta name="DCTERMS.provenance" content="" xml:lang="en-US"/><meta name="DCTERMS.subject" content="," xml:lang="en-US"/><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en"/><link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" hreflang="en"/><link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en"/><link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en"/><style type="text/css">
@page { }
table { border-collapse:collapse; border-spacing:0; empty-cells:show }
td, th { vertical-align:top; font-size:12pt;}
h1, h2, h3, h4, h5, h6 { clear:both }
ol, ul { margin:0; padding:0;}
li { list-style: none; margin:0; padding:0;}
<!-- "li span.odfLiEnd" - IE 7 issue-->
li span. { clear: both; line-height:0; width:0; height:0; margin:0; padding:0; }
span.footnodeNumber { padding-right:1em; }
span.annotation_style_by_filter { font-size:95%; font-family:Arial; background-color:#fff000; margin:0; border:0; padding:0; }
* { margin:0;}
.P1 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#808080; }
.P10 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P11 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P12 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P13 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P14 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P15 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P16 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P17 { font-size:22pt; font-family:Calibri; writing-mode:page; color:#eeeeee; background-color:#000000; }
.P18 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P19 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P20 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P21 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P22 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P23 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P24 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P25 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P26 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P27 { font-size:12pt; font-family:Courier 10 Pitch; writing-mode:page; color:#006600; }
.P28 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P29 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P3 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P30 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P31 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P32 { font-size:12pt; font-family:Calibri; writing-mode:page; color:#000000; }
.P33 { font-size:22pt; font-family:Calibri; writing-mode:page; color:#eeeeee; background-color:#000000; }
.P4 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P5 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P6 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P7 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P8 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.P9 { font-size:12pt; font-family:Calibri; writing-mode:page; }
.Bullet_20_Symbols { font-family:OpenSymbol; }
.T9 { font-family:Courier 10 Pitch; }
<!-- ODF styles with no properties representable as CSS -->
.T1 .T10 .T11 .T12 .T2 .T3 .T4 .T5 .T6 .T7 .T8 { }
</style></head><body dir="ltr" style="max-width:21.001cm;margin-top:2cm; margin-bottom:2cm; margin-left:1cm; margin-right:1cm; "><p class="P17">About imamLL</p><p class="P3"> </p><p class="P12">What is Imam Linear List (imamLL)?</p><p class="P12"> </p><p class="P12"><span class="T1">ImamLL is a</span> simple linked list implementation <span class="T3">library</span> <span class="T1">for C programming language</span>. <span class="T1">It</span> <span class="T1">is</span> designed to be efficient and programmers friendly by minimizing number of variables required for allocating and deallocating memory from the heap. <span class="T1">It is created in a hope that it will help developers to store arbitrary information in the programs easily.</span></p><p class="P12"> </p><p class="P13">Where can I use imamLL ?</p><p class="P13"> </p><p class="P13">You can use imamLL whenever you need to create data list<span class="T7">s</span> in your program<span class="T7">s</span>. Since imamLL is pointer based, it will accept any type of data and also data of arbitrary sizes into a single list. You can easily add, remove, modify and get data from the list<span class="T1">s</span>.</p><p class="P13"> </p><p class="P14">What are the features of imamLL ?</p><p class="P14"> </p><ul><li><p class="P28" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>Dynamically allocat<span class="T2">e</span> data at any given point in <span class="T2">the</span> program runtime<span class="odfLiEnd"/> </p></li><li><p class="P29" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>Add elements of arbitrary sizes into the lists<span class="odfLiEnd"/> </p></li><li><p class="P28" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>Navigate through the <span class="T2">elements</span> in both forward and backward<span class="odfLiEnd"/> </p></li><li><p class="P30" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>Add, remove, modify and get elements from the lists<span class="odfLiEnd"/> </p></li></ul><p class="P15"> </p><p class="P16">What are the future plans for imamLL ?</p><p class="P16"> </p><ul><li><p class="P31" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>Thread safety<span class="odfLiEnd"/> </p></li><li><p class="P32" style="margin-left:0cm;"><span class="Bullet_20_Symbols" style="display:block;float:left;min-width:0.635cm;">•</span>and many more<span class="odfLiEnd"/> </p></li></ul><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P4"> </p><p class="P33">The Basics</p><p class="P5"> </p><p class="P5">There are two structures in imamLL library, a data list and a list element. The <span class="T9">struct imamLL</span> structure stores basic information about a list for example number of elements in <span class="T8">a</span> list, total number of bytes allocated by list elements, addresses of first, last and current list elements. The definition of the imamLL structure is shown below:</p><p class="P5"> </p><p class="P19">struct imamLL {</p><p class="P19"> long number_of_elements; /* number of elements in the list */</p><p class="P19"> long size; /* total elements size in bytes */</p><p class="P19"> struct imamLL_element *first; /* pointer to the first element */</p><p class="P19"> struct imamLL_element *last; /* pointer to the last element */</p><p class="P19"> struct imamLL_element *current; /* pointer to an arbitrary <span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> element, used by</span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> imamLL_element_get_* functions */</span></p><p class="P19"> int error; /* error number used by <span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> imamLL_list_error function */</span></p><p class="P19">};</p><p class="P5"> </p><p class="P6">The <span class="T9">struct imamLL_element</span> structure stores information about each individual element in a list. <span class="T4">The definition of the </span>imamLL_element structure <span class="T4">is shown below:</span></p><p class="P6"> </p><p class="P20">struct imamLL_element {</p><p class="P20"> void *data; /* pointer to the data */</p><p class="P20"> long size; /* size of data in bytes */</p><p class="P20"> struct imamLL_element *prev; /* pointer to the next element */</p><p class="P20"> struct imamLL_element *next; /* pointer to the first element */</p><p class="P20">};</p><p class="P7"> </p><p class="P8">To create a list of data, first we need to declare a pointer of type <span class="T9">struct imamLL</span>. For example, we want a create an integer number<span class="T10">s</span> list, therefore <span class="T6">we</span> declare a pointer named num_list as follows:</p><p class="P8"> </p><p class="P21">struct imamLL *num_list;</p><p class="P8"> </p><p class="P8">Next, we have to allocate memory for the list by calling <span class="T10">the</span> function <span class="T9">imamLL_list_create</span>, <span class="T10">while</span> will return a pointer to the list,</p><p class="P8"> </p><p class="P21">num_list = imamLL_list_create ();</p><p class="P8"> </p><p class="P8">Now, to add an integer number to the list we use <span class="T9">imamLL_element_add</span> function. <span class="T9">imamLL_element_add</span> function allocates memory for an element and returns a pointer to the element. So first, we declare a pointer of type <span class="T9">struct imamLL_element</span> and call <span class="T9">imamLL_element_add</span> function.</p><p class="P8"> </p><p class="P21">struct imamLL_element *element;</p><p class="P21"> </p><p class="P21">element = <a name="__DdeLink__21_629666357"/>imamLL_element_add (num_list, sizeof (int), <span class="T6">0</span>);</p><p class="P9"><span class="T6">The arguments in </span><span class="T9">imamLL_element_add</span> <span class="T6">are pointer of the list, size of the element in bytes, and 0 for indicating element to be added at the bottom of the list. Finally, we can store an integer value to the element by,</span></p><p class="P9"> </p><p class="P23">*((int *)element->data) = 10;</p><p class="P10"> </p><p class="P10">We can store more integer values by adding more elements in the list by repeating the above codes, for example:</p><p class="P10"> </p><p class="P22">element = <a name="__DdeLink__21_6296663573"/>imamLL_element_add (num_list, sizeof (int), <span class="T6">0</span>);</p><p class="P23">*((int *)element->data) = 20;</p><p class="P22"> </p><p class="P22">element = <a name="__DdeLink__21_62966635734"/>imamLL_element_add (<a name="__DdeLink__32_629666357"/>num_list, sizeof (int), <span class="T6">0</span>);</p><p class="P23">*((int *)element->data) = 30;</p><p class="P10"> </p><p class="P11">Now, we have three elements in the list having integer values 10, 20 and 30 respectively. We can print all the values in the list elements by using the following code:</p><p class="P11"> </p><p class="P24">imamLL_list_rewind (student_list);</p><p class="P24"> </p><p class="P24">while ((element = imamLL_element_get_next(student_list)) != NULL) {</p><p class="P24"><span> printf ("%d\n", *((int *)element->data));</span></p><p class="P24">}</p><p class="P11"> </p><p class="P11">The function <span class="T9">imamLL_list_rewind</span>, sets the current element in the list to be first element and <span class="T9">imamLL_element_get_next</span> function returns the next element <span class="T11">from</span> the current element. The <span class="T9">imamLL_element_get_next</span> function returns NULL when the end of the list is reached. </p><p class="P11"> </p><p class="P11">When we do not the need the list, we can free the memory associated with <span class="T11">the</span> list and it's elements by using:</p><p class="P11"> </p><p class="P24">imamLL_list_destroy (<span class="T5">num_list</span>);</p><p class="P11"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18"> </p><p class="P18">The <span class="T12">full blown</span> code of the example <span class="T12">program</span> is given below:</p><p class="P18"> </p><p class="P27">#include <stdio.h></p><p class="P27">#include <stdlib.h></p><p class="P27">#include <string.h></p><p class="P27"> </p><p class="P27">#include <imamll.h><span> </span><span> /*header for imamLL */</span></p><p class="P27"> </p><p class="P27">struct imamLL *<span class="T5">num_list</span> = NULL;</p><p class="P27">struct imamLL_element *element = NULL;</p><p class="P27"> </p><p class="P27">int main (int argc, char** argv)</p><p class="P27">{</p><p class="P27"><span class="T5"> num_list</span> = imamLL_list_create();</p><p class="P27"><span> </span></p><p class="P27"><span> if ( <span class="T5">num_list</span> == NULL) {</span></p><p class="P27"><span> </span><span> printf ("Can not create the list\n");</span></p><p class="P27"><span> </span><span> exit (EXIT_FAILURE);</span></p><p class="P27"><span> }</span></p><p class="P27"> </p><p class="P27"><span class="T5"> element = </span><a name="__DdeLink__21_6296663576"/><span class="T5">imamLL_element_add</span><span class="T5"> (num_list, sizeof (int), 0);</span></p><p class="P27"> </p><p class="P27"><span class="T5"> if (element == NULL) printf ("Error allocating memory for a</span>n <span> integer element<span class="T5">\n");</span></span></p><p class="P27"><span class="T5"> e</span>lse <span class="T6">*((int *)element->data) = 10;</span></p><p class="P27"> </p><p class="P27"><span> <span class="T5">element = </span><a name="__DdeLink__21_62966635767"/><span class="T5">imamLL_element_add</span><span class="T5"> (num_list, sizeof (int), 0);</span></span></p><p class="P27"> </p><p class="P27"><span class="T5"> if (element == NULL) printf ("Error allocating memory for a</span>n <span> integer element<span class="T5">\n");</span></span></p><p class="P27"><span class="T5"> e</span>lse <span class="T6">*((int *)element->data) = </span>2<span class="T6">0;</span></p><p class="P27"> </p><p class="P27"><span class="T5"> element = </span><a name="__DdeLink__21_62966635768"/><span class="T5">imamLL_element_add</span><span class="T5"> (num_list, sizeof (int), 0);</span></p><p class="P27"> </p><p class="P27"><span class="T5"> if (element == NULL) printf ("Error allocating memory for a</span>n <span> integer element<span class="T5">\n");</span></span></p><p class="P27"><span class="T5"> else *((int *)element->data) = </span>3<span class="T6">0;</span></p><p class="P27"> </p><p class="P26"><span> imamLL_list_rewind (<span class="T5">num_list</span>);</span></p><p class="P25"> </p><p class="P26"><span> while ((element = imamLL_element_get_next(<span class="T5">num_list</span>)) != NULL) {</span></p><p class="P25"><span> </span><span> printf ("%d\n", *((int *)element->data));</span></p><p class="P25"><span> }</span></p><p class="P27"> </p><p class="P25"><span> imamLL_list_destroy (<span class="T5">num_list</span>);</span></p><p class="P25"> </p><p class="P27"><span> return 0;</span></p><p class="P27">}</p></body></html>