File: README_CVector.html

package info (click to toggle)
cvector 1.0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 200 kB
  • sloc: ansic: 367; makefile: 301
file content (269 lines) | stat: -rw-r--r-- 12,948 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<html>
<head>
<title>README CVector -- API for Dynamic Arrays</title>
</head>
<body bgcolor="FFFFFF">
<font face="Arial,Helevtica,Times" size=4>
<a href="http://sourceforge.net/projects/cvector"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=247254&amp;type=13" width="120" height="30" alt="Get CVector at SourceForge.net. Fast, secure and Free Open Source software downloads" /></a>
<hr>
<h3 align="center">CVector -- ANSI C API for Dynamic Arrays</h3>
<P>
<center>
Release 1.0.4.1<br />
1 May 2018<br />
&#169; 2008, 2009, 2014 Herbert J. Bernstein<br/>
<script language="javascript" type="text/javascript">
<!-- 
      var name = "yaya";
      var domain = "bernstein-plus-sons";
      var domext = "com";
      document.write ("<a href=\"mailto:" + name + "@" + domain + "." + domext + "\"style=\"text-decoration:none\">" + name + " <b>at</b> " + domain + " <b>dot</b> " + domext+"</a>");
// -->
</script>
<noscript>
yaya <b>at</b> bernstein-plus-sons <b>dot</b> com
</noscript><br />
You may distribute the CVector API under the <a href=lgpl.txt style="text-decoration:none">LGPL</a><br />
</center>
<P>
CVector is an ANSI C implementation of dynamic arrays to provide a crude approximation to the C++ vector class.
<p>
Release 1.0.4.1 is a move from Sourceforge to Github.
Release 1.0.4 adds a CMakeLists.txt file to the kit and changes the test program to allow normal output to be written to a specified file.
Release 1.0.3 was is a minor revision of release 1.0.0 of 8 January 2009 to update the Makefile for builds under MINGW,
on 26 February 2009 to add the macro CVectorElementAt, and on 7 July 2009 to change the  macro to CVECTOR_FAR and
similarly change the macros that handle memmove and memset.  There
are no changes to the code.  The internal copy of libtool has been removed.
<p>
<h4>Installation</h4>
<p>
The CVector package is available on Github at <a href="https://github.com/yayahjb/cvector">https://github.com/yayahjb/cvector</a>. 
<P>
To see the current settings for a build
execute
<p>
make
</p>
which should give the following information:
<p>
<pre><tt>
PLEASE READ README_CVector.txt and lgpl.txt
 
 Before making the CVector library and example programs, check
 that the chosen settings are correct
 
 The current compile command is:
 
   libtool --mode=compile gcc -g -O2  -Wall -ansi -pedantic -I.  -c
 
 The current library link command is:
 
   libtool --mode=link  gcc -version-info 2:0:0 -release 1.0.4 -rpath /usr/local/lib
 
 The current library local, dynamic and static build commands are:
 
   libtool --mode=link gcc -g -O2  -Wall -ansi -pedantic -I.
   libtool --mode=link gcc -g -O2  -Wall -ansi -pedantic -shared -I /usr/local/include
   libtool --mode=link gcc -g -O2  -Wall -ansi -pedantic -static -I /usr/local/include
 
 Before installing the CVector library and example programs, check
 that the install directory and install commands are correct:
 
 The current values are :
 
   /usr/local
   libtool --mode=install cp 
    
 
 To compile the CVector library and example programs type:
 
   make clean
   make all
 
 To run a set of tests type:
 
   make tests
 
 To clean up the directories type:
 
   make clean
 
 To install the library and binaries type:
   
   make install

</tt>
</pre>
<p>
If these settings need to be changed, edit Makefile.  On some systems, e.g. Mac OS X, the default
libtool is not appropriate.  In that case you should install a recent version of libtool.  The
CVector kit has been tested with libtool versions 1.3.5, 1.5.4 and 2.2.6.  If the system libtool is
not to be used, define the variable LIBTOOL to be the path to the libtool executable, e.g.
in bash.  On MINGW, use of gcc 4 and libtool 2.2.6 are highly recommended.
<p>
export LIBTOOL=$HOME/bin/libtool
<p>
of in the Makefie
<p>
LIBTOOL = $(HOME)/bin/libtool
<p>
If you need to include local header files using #include &quot;...&quot; instead of #include &lt;...&gt;,
define the variable USE_LOCAL_HEADERS


<h4>Synopsis</h4>
<P>
<b>#include &lt;CVector.h&gt;</b>
<P>    
    <b>int</b> <br /><b>CVectorCreate</b>(<b>CVectorHandle</b> <i>*</i> <i>vectorhandle</i>, <b>const</b> <b>size_t</b> <i>elementsize</i>, <b>const</b> <b>size_t</b> <i>capacity</i>);
<p>    
    <b>int</b> <br /><b>CVectorAddElement</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>const</b>  <b>void</b> <i>*</i> <i>element</i>);
<p>    
    <b>void *</b> <br /><b>CVectorElementAt</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>const</b> <b>size_t</b> <i>index</i>);
<p>    
    <b>int</b> <br /><b>CVectorGetElement</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>,  <b>void</b> <i>*</i> <i>element</i>, <b>const</b> <b>size_t</b> <i>index</i>);
<p>    
    <b>int</b> <br /><b>CVectorGetElementptr</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>,  <b>void</b> <i>*</i>* <i>elementptr</i>, <b>const</b> <b>size_t</b> <i>index</i>);
<p>    
    <b>int</b> <br /><b>CVectorSetElement</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>,  <b>void</b> <i>*</i> <i>element</i>, <b>const</b> <b>size_t</b> <i>index</i>);
<p>    
    <b>int</b> <br /><b>CVectorRemoveElement</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>const</b> <b>size_t</b> <i>index</i>);
<p>    
    <b>int</b> <br /><b>CVectorClear</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>);
<p>    
    <b>int</b> <br /><b>CVectorFree</b>(<b>CVectorHandle</b> <i>*</i> <i>vectorhandle</i>);
<p>    
    <b>size_t</b> <br /><b>CVectorCapacity</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>);    
<p>    
    <b>int</b> <br /><b>CVectorGetCapacity</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>size_t</b> <i>*</i> <i>capacity</i>);
<p>    
    <b>size_t</b>  <br /><b>CVectorSize</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>);
<p>
    
    <b>int</b> <br /><b>CVectorGetSize</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>size_t</b> <i>*</i> <i>size</i>);
<p>
    
    <b>int</b> <br /><b>CVectorGetFlags</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>int</b> <i>*</i> <i>flags</i>);
<p>
    
    <b>int</b> <br /><b>CVectorSetCapacity</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>const</b> <b>size_t</b> <i>capacity</i>);       
<p>
    
    <b>int</b> <br /><b>CVectorSetSize</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>const</b> <b>size_t</b> <i>size</i>);
<p>
    
    <b>int</b> <br /><b>CVectorSetFlags</b>(<b>const</b> <b>CVectorHandle</b> <i>vectorhandle</i>, <b>const</b> <b>unsigned</b> <b>int</b> <i>flags</i>);
<p>
<h4>Description</h4>
<P>
The CVector.h header file defines the <b>CVectorHandle</b> type as a dynamic array for elements in which each element uses <i>elementsize</i>
characters in a block of memory <i>elementsize</i>*<i>capacity</i> characters long.  There are <i>size</i> elements used in the array
each with an <i>index</i> between 0 and <i>size</i>-1.  <b>CVectorCreate</b>() is used to create the dynamic array.  Elements may either be 
added at the end of the dynamic array using <b>CVectorAddElement</b>(), or in arbitrary order with <b>CVectorSetElement</b>().  Elements may
be examined with copy semantics using <b>CVectorGetElement</b>() or as pointers directly into the dynamic array using <b>CVectorGetElementptr</b>().
The function <b>CVectorElementAt</b>() performs the same function as  <b>CVectorGetElementptr</b>() for use in complex expressions, but
does no error checking.
Caution must be used in using pointers because expansion of the dynamic array can force relocation of all data in the dynamic array.  Therefore,
any use of <b>CVectorGetElementptr</b>() sets a flag, CVECTOR_FLAGS_NO_RELOCATION, that disables any further array relocation, which will prevent
the extension of the <i>size</i> array beyond the <i>capacity</i> in effect at the time of the first <b>CVectorGetElementptr</b>() call.  Calls
to <b>CVectorElementAt</b>() do not set CVECTOR_FLAGS_NO_RELOCATION and returning resulting values to calling routines is dangerous.  The functions
<b>CVectorGetFlags</b>() and <b>CVectorSetFlags</b>() can be used to reset this flag (see Examples below).  The function <b>CVectorRemoveElement</b>()
will remove the element of the indicated <i>index</i>, shifting all elements of higher indices down, unless the flag CVECTOR_FLAGS_NO_RELOCATION is set.
The capacity, size and flags may be examined or set with <b>CVectorCapacity</b>(), <b>CVectorGetCapacity</b>(), <b>CVectorSize</b>(), 
<b>CVectorGetSize</b>(), <b>CVectorGetFlags</b>, <b>CVectorSetCapacity</b>(), <b>CVectorSetSize</b>() and <b>CVectorSetFlags()</b>.

<p>
External declarations as well as the CVector structure definition, and the CVectorHandle definition are included in the &lt;<i>CVector.h</i>&gt; 
include file.  The CVector structure includes at least the following fields:
<p>
<blockquote>
<table border="0">
         <tr><td>size_t size;             </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* size of the vector      */</td></tr>
         <tr><td>size_t capacity;         </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* capacity of the vector  */</td></tr>
         <tr><td>size_t elementsize;      </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* size of an element      */</td></tr>
         <tr><td>void * array;            </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* the array of elements   */</td></tr>
         <tr><td>int flags;               </td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* flags                   */</td></tr>
</table>
</blockquote>
</p>
<p>
The valid flags are CVECTOR_FLAGS_NO_RELOCATION  and CVECTOR_FLAGS_NO_RESIZE which may be ORed.
</p>
<p>
<h4>Returns</h4>
<p>
The functions <b>CVectorCapacity</b>() and <b>CVectorSize</b>() are implemented as macros and return the CVector <i>capacity</i> and
<i>size</i> directly.  While they could be used as lvalues, such use is not recommended and is not guaranteed to work in future versions
of CVector.  The function <b>CVectorElementAt</b>() is implemented as a macro and returns a <i>void *</i> pointer into the data array
with no bounds checking.   All other functions return 0 for normal completion, or the sum of one or more of the following non-zero error codes:
<p>
<blockquote>
<table border="0">
         <tr><td>Error Return          </td><td>Numeric Value              </td><td>&nbsp;&nbsp;&nbsp;Meaning</td></tr>
         <tr><td>CVECTOR_MALLOC_FAILED </td><td>&nbsp;&nbsp;&nbsp;-1       </td><td>&nbsp;&nbsp;&nbsp;/* A call to allocate memory failed  */</td></tr>
         <tr><td>CVECTOR_BAD_ARGUMENT  </td><td>&nbsp;&nbsp;&nbsp;-2       </td><td>&nbsp;&nbsp;&nbsp;/* An argument is not valid          */</td></tr>
         <tr><td>CVECTOR_NOT_FOUND     </td><td>&nbsp;&nbsp;&nbsp;-4       </td><td>&nbsp;&nbsp;&nbsp;/* An element could not be found     */</td></tr>
         <tr><td>CVECTOR_NO_RELOCATION </td><td>&nbsp;&nbsp;&nbsp;-8       </td><td>&nbsp;&nbsp;&nbsp;/* Relocation is not permitted       */</td></tr>
         <tr><td>CVECTOR_NO_RESIZE     </td><td>&nbsp;&nbsp;&nbsp;-16      </td><td>&nbsp;&nbsp;&nbsp;/* A change is size is not permitted */</td></tr>

</table>
</blockquote>
</p>
<p>
<h4>Examples</h4>
<p>
To create a vector of doubles, starting with minimal capacity, reporting failure to stderr:
<P>
<pre><tt>
        #include &lt;CVector.h&gt;
        ...
        CvectorHandle vectorhandle;
        ...
        if (CVectorCreate(&vectorhandle,sizeof(double),1)) fprintf(stderr," CVectorCreate failed!!\n");
</tt></pre>
<P>
To create a vector of arrays of or pointers to doubles:
<P>
<pre><tt>
        #include &lt;CVector.h&gt;
        ...
        CvectorHandle vectorhandle;
        ...
        if (CVectorCreate(&vectorhandle,sizeof(double *),1)) fprintf(stderr," CVectorCreate failed!!\n");
</tt></pre>
<p>
To pop the last element of a vector of doubles:
<p>
<pre><tt>
        #include &lt;CVector.h&gt;
        ...
        CvectorHandle vectorhandle;
        double element;
        ...
        if (CVectorGetElement(vectorhandle, &element, (CVectorSize(vectorhandle)-1)) 
            fprintf(stderr," Failed CVectorGetElement);
        if (CVectorRemoveElement(vectorhandle,  (CVectorSize(vectorhandle)-1)) 
            fprintf(stderr," Failed CVectorRemoveElement);
</tt></pre>

<p>
See the test program <a href="CVectorBasicTest.c">CVectorBasicTest.c</a>

<hr>
<font size="2">
Updated 1 May 2018<br />
<script language="javascript" type="text/javascript">
<!-- 
      var name = "yaya";
      var domain = "bernstein-plus-sons";
      var domext = "com";
      document.write ("<a href=\"mailto:" + name + "@" + domain + "." + domext + "\" style=\"text-decoration:none\">" + name + " <b>at</b> " + domain + " <b>dot</b> " + domext+"</a>");
// -->
</script>
<noscript>
yaya <b>at</b> bernstein-plus-sons <b>dot</b> com
</noscript>
</font>
</font>
</body>
</html>