This implements the ararylist container arraylist.c
----------------------------------------------------
#include "containers.h"
static int GetCount( ArrayList *AL);
static int IsReadOnly( ArrayList *AL);
static int SetReadOnly( ArrayList *AL,int newval);
static int Add( ArrayList *AL,void *newval);
static int AddRange( ArrayList *AL,void **newvalues);
static int Clear( ArrayList *AL);
static bool Contains( ArrayList *AL,void *str);
static void **CopyTo( ArrayList *AL);
static int IndexOf( ArrayList *AL,void *SearchedElement);
static int Insert( ArrayList *AL,void *);
static int InsertAt( ArrayList *AL,int idx,void *newval);
static void *IndexAt( ArrayList *AL,int idx);
static int Remove( ArrayList *AL,void *);
static int RemoveAt( ArrayList *AL,int idx);
static int Finalize( ArrayList *AL);
static int GetCapacity( ArrayList *AL);
static bool SetCapacity( ArrayList *AL,int newCapacity);
static void Apply(ArrayList *AL,int(*Applyfn)(void *,void *),void *arg);
static int Push(ArrayList *AL,void *str);
static void *Pop(ArrayList *AL);
static void *ReplaceAt(ArrayList *AL,int idx,void *newval);
static int IsCaseSensitive(ArrayList *AL);
static int SetCaseSensitive(ArrayList *AL,int newval);
static ArrayListInterface lpVtableAL = {
GetCount, IsReadOnly, SetReadOnly, Add, AddRange, Clear, Contains,
CopyTo, IndexOf, Insert, InsertAt, IndexAt, Remove, RemoveAt,
Finalize, GetCapacity, SetCapacity, Apply, Push, Pop, ReplaceAt,
};
#ifndef NO_GC
#include <gc.h>
#define MALLOC GC_malloc
#define FREE(a)
#else
#include <stdlib.h>
#define MALLOC malloc
#define FREE free
#endif
#ifndef DEFAULT_START_SIZE
#define DEFAULT_START_SIZE 20
#endif
static void *DuplicateElement(void *str,int size)
{
if (str == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_BADARG);
return NULL;
}
void *result = MALLOC(size);
if (result == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_NOMEMORY);
return NULL;
}
else memcpy(result,str,size);
return result;
}
#define AL_READONLY 1
#define AL_IGNORECASE 2
#define CHUNKSIZE 20
ArrayList newArrayList(size_t elementsize,int startsize)
{
ArrayList result;
if ((elementsize &0x800000) || elementsize == 0)
ContainerRaiseError(__func__,CONTAINER_ERROR_BADARG);
memset(&result,0,sizeof(result));
result.count = 0;
if (startsize <= 0)
startsize = DEFAULT_START_SIZE;
result.contents = MALLOC(startsize*elementsize);
if (result.contents == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_NOMEMORY);
}
else {
memset(result.contents,0,elementsize*startsize);
result.capacity = startsize;
result.lpVtbl = &lpVtableAL;
result.ElementSize = elementsize;
}
return result;
}
static int GetCount(ArrayList *AL)
{
return AL->count;
}
static int IsReadOnly(struct _ArrayList *AL)
{
return AL->flags & AL_READONLY ? 1 : 0;
}
static int SetReadOnly(struct _ArrayList *AL,int newval)
{
int oldval = AL->flags & AL_READONLY ? 1 : 0;
if (newval)
AL->flags |= AL_READONLY;
else
AL->flags &= ~AL_READONLY;
return oldval;
}
static int Resize(ArrayList *AL)
{
int newcapacity = AL->capacity + CHUNKSIZE;
void **oldcontents = AL->contents;
AL->contents = MALLOC(newcapacity*sizeof(void *));
if (AL->contents == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_NOMEMORY);
AL->contents = oldcontents;
return 0;
}
memset(AL->contents,0,sizeof(void *)*newcapacity);
memcpy(AL->contents,oldcontents,AL->count*sizeof(void *));
AL->capacity = newcapacity;
FREE(oldcontents);
return 1;
}
static int Add(ArrayList *AL,void *newval)
{
if (AL->flags & AL_READONLY)
return -1;
if (newval == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_BADARG);
return -2;
}
if (AL->count >= AL->capacity) {
if (!Resize(AL))
return 0;
}
AL->contents[AL->count] = DuplicateElement(newval,AL->ElementSize);
if (AL->contents[AL->count] == NULL) {
return 0;
}
AL->count++;
return AL->count;
}
static int AddRange(struct _ArrayList * AL,void **data)
{
int i = 0,c;
if (AL->flags & AL_READONLY)
return 0;
if (data == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_BADARG);
return -2;
}
c = AL->count;
while (data[i] != NULL) {
int r = Add(AL,data[i]);
if (r <= 0) {
while (AL->count > c) {
Pop(AL);
}
return r;
}
i++;
}
return AL->count;
}
static int Clear(struct _ArrayList *AL)
{
int oldval = AL->count;
if (AL->flags & AL_READONLY)
return 0;
for (int i=0; i<AL->count;i++) {
FREE(AL->contents[i]);
AL->contents[i] = NULL;
}
AL->count = 0;
return oldval;
}
static bool Contains(ArrayList *AL,void *str)
{
if (str == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_BADARG);
return false;
}
for (int i = 0; i<AL->count;i++) {
if (!memcmp(AL->contents[i],str,AL->ElementSize))
return true;
}
return false;
}
static void **CopyTo(ArrayList *AL)
{
void **result = MALLOC(AL->count*sizeof(void *));
int i;
if (result == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_NOMEMORY);
return NULL;
}
for (i=0; i<AL->count;i++) {
result[i] = DuplicateElement(AL->contents[i],AL->ElementSize);
if (result[i] == NULL) {
return NULL;
}
}
result[i] = NULL;
return result;
}
static int IndexOf(ArrayList *AL,void *str)
{
int i;
if (str == NULL)
return -1;
for (i=0; i<AL->count;i++) {
if (!memcmp(AL->contents[i],str,AL->ElementSize)) {
return i;
}
}
return -1;
}
static void *IndexAt(ArrayList *AL,int idx)
{
if (idx >=AL->count || idx < 0) {
ContainerRaiseError(__func__,CONTAINER_ERROR_BADARG);
return NULL;
}
return AL->contents[idx];
}
#if 0
// Under lcc-win you can use the more natural [ ] syntax.
void *operator[](ArrayList *AL,int idx)
{
return IndexAt(AL,idx);
}
#endif
static int InsertAt(ArrayList *AL,int idx,void *newval)
{
if (AL->flags & AL_READONLY)
return 0;
if (idx < 0 || idx > AL->count) {
ContainerRaiseError(__func__,CONTAINER_ERROR_INDEX);
return -1;
}
if (AL->count >= (AL->capacity-1)) {
if (!Resize(AL))
return 0;
}
if (idx == 0) {
if (AL->count > 0)
memmove(AL->contents+1,AL->contents,AL->count*sizeof(void *));
AL->contents[0] = newval;
}
else if (idx == AL->count) {
AL->contents[idx] = newval;
}
else if (idx < AL->count) {
memmove(AL->contents+idx+1,AL->contents+idx,(AL->count-idx+1)*sizeof(void *));
AL->contents[idx] = newval;
}
AL->count++;
return AL->count;
}
static int Insert(ArrayList *AL,void *newval)
{
if (AL->flags & AL_READONLY)
return 0;
return InsertAt(AL,0,newval);
}
static int RemoveAt(ArrayList *AL,int idx)
{
if (idx >= AL->count || idx < 0 || (AL->flags & AL_READONLY))
return -1;
if (AL->count == 0)
return -2;
FREE(AL->contents[idx]);
if (idx < (AL->count-1)) {
memmove(AL->contents+idx,AL->contents+idx+1,
(AL->count-idx)*sizeof(void *));
}
AL->contents[AL->count-1]=NULL;
AL->count--;
return AL->count;
}
static int Remove(ArrayList *AL,void *str)
{
int idx = IndexOf(AL,str);
if (idx < 0)
return idx;
return RemoveAt(AL,idx);
}
static int Push(ArrayList *AL,void *str)
{
void *r;
if (AL->flags&AL_READONLY)
return 0;
if (AL->count >= AL->capacity-1) {
if (!Resize(AL))
return 0;
}
r = DuplicateElement(str,AL->ElementSize);
if (r == NULL)
return 0;
AL->contents[AL->count++] = r;
return AL->count;
}
static void * Pop(ArrayList *AL)
{
void *result;
if ((AL->flags&AL_READONLY) || AL->count == 0)
return NULL;
AL->count--;
result = AL->contents[AL->count];
AL->contents[AL->count] = NULL;
return result;
}
static int Finalize(ArrayList *AL)
{
int result = AL->count;
for (int i=0; i<AL->count;i++) {
FREE(AL->contents[i]);
}
FREE(AL->contents);
FREE(&AL);
return result;
}
static int GetCapacity(ArrayList *AL)
{
return AL->capacity;
}
static bool SetCapacity(struct _ArrayList *AL,int newCapacity)
{
if (AL->count != 0)
return false;
FREE(AL->contents);
AL->contents = MALLOC(newCapacity*sizeof(void *));
if (AL->contents == NULL) {
ContainerRaiseError(__func__,CONTAINER_ERROR_NOMEMORY);
return false;
}
memset(AL->contents,0,sizeof(void *)*newCapacity);
AL->capacity = newCapacity;
return 1;
}
static void Apply(struct _ArrayList *AL,int (*Applyfn)(void *,void *),void *arg)
{
for (int i=0; i<AL->count;i++) {
Applyfn(AL->contents[i],arg);
}
}
#if 0
// Under lcc-win you can use the more natural [ ] syntax
void * __declspec(naked) operator[]=(ArrayList *AL,int idx,void *newval)
{
}
#endif
static int ReplaceAt(ArrayList *AL,int idx,void *newval)
{
if (AL->flags & AL_READONLY)
return 0;
if (idx < 0 || idx > AL->count)
return 0;
FREE(AL->contents[idx]);
AL->contents[idx] = newval;
return 1;
}
#if 0
void *operator[]=(ArrayList AL,int idx,void *newval)
{
return ReplaceAt(AL,idx,newval);
}
#endif
#ifdef TEST
#include <stdio.h>
static void PrintArrayList(ArrayList *AL)
{
printf("Count %d, Capacity %d\n",AL->count,AL->capacity);
for (int i=0; i<AL->count;i++) {
printf("%s\n",AL[i]);
}
printf("\n");
}
int main(void)
{
ArrayList AL = newArrayList();
char *p;
AL.lpVtbl->Add(&AL,"Martin");
AL.lpVtbl->Insert(&AL,"Jakob");
if (!AL.lpVtbl->Contains(&AL,"Martin")) {
printf("error, string not found!\n");
}
printf("Count should be 2, is %d\n",AL->GetCount());
PrintArrayList(&AL);
AL.lpVtbl->InsertAt(1,"Position 1");
AL.lpVtbl->InsertAt(2,"Position 2");
PrintArrayList(AL);
AL.lpVtbl->Remove("Jakob");
PrintArrayList(AL);
AL.lpVtbl->Push("pushed");
PrintArrayList(&AL);
AL.lpVtbl->Pop();
PrintArrayList(AL);
p = AL[1];
printf("Item position 1:%s\n",p);
PrintArrayList(&AL);
}
#endif
|
|
0
|
|
|
|
Reply
|
jacob24 (973)
|
9/28/2009 10:11:50 AM |
|
Sorry, an error in line 23:
Should be:
static int ReplaceAt(ArrayList *AL,int idx,void *newval);
|
|
0
|
|
|
|
Reply
|
jacob24 (973)
|
9/28/2009 11:30:01 AM
|
|
"jacob navia" <jacob@nospam.org> wrote in message
news:h9q6ne$1l3$1@aioe.org...
> Sorry, an error in line 23:
> Should be:
> static int ReplaceAt(ArrayList *AL,int idx,void *newval);
I am curious as to why you are using a signed type for the `idx' parameter?
IVMHO, it would be "easier" to use `size_it's, or some other unsigned type
because you don't have to always check to see if the index is less than
zero.
|
|
0
|
|
|
|
Reply
|
no6 (2791)
|
9/29/2009 12:25:50 AM
|
|
In <h9rk6d$290l$1@news.ett.com.ua>, Chris M. Thomasson wrote:
> "jacob navia" <jacob@nospam.org> wrote in message
> news:h9q6ne$1l3$1@aioe.org...
>> Sorry, an error in line 23:
>> Should be:
>> static int ReplaceAt(ArrayList *AL,int idx,void *newval);
>
> I am curious as to why you are using a signed type for the `idx'
> parameter? IVMHO, it would be "easier" to use `size_it's, or some
> other unsigned type because you don't have to always check to see if
> the index is less than zero.
size_t has another advantage, when specifying ranges of objects:
(size_t)-1 can be used to mean "...to the end of the list". For the
sake of a simple example, let's take a simple null-terminated string
routine for replacing a range of characters:
#include <string.h>
#include "mystring.h" /* no, I haven't, have I? - so write your own */
void str_overwrite(char *s, size_t start, size_t onepastend, char ch)
{
size_t len = 0;
assert(s != NULL);
assert(start < onepastend);
len = strlen(s);
if(onepastend > len)
{
onepastend = len;
}
while(start < onepastend)
{
s[start++] = ch;
}
}
(Clearly, a container library won't need to do the (container
equivalent of) strlen, as the length will already be written down
somewhere.)
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
|
|
0
|
|
|
|
Reply
|
rjh (10789)
|
9/29/2009 12:46:53 AM
|
|
Just saying that the ability to change an object from being read-only
to being modifiable makes some very important optimisations (like very
fast copying) impossible. Read up on Apple's Core Foundation library
(which is in actual use by a significant number of users).
|
|
0
|
|
|
|
Reply
|
christian.bau1 (403)
|
9/29/2009 7:34:39 AM
|
|
christian.bau a �crit :
> Just saying that the ability to change an object from being read-only
> to being modifiable makes some very important optimisations (like very
> fast copying) impossible. Read up on Apple's Core Foundation library
> (which is in actual use by a significant number of users).
How do you destroy a read-only object?
You *must* change it to read/write!
I do not see how you could initially add objects to a read only
list. You *have* to get rid of the read-only flag when initializing
and when destroying the object.
|
|
0
|
|
|
|
Reply
|
jacob24 (973)
|
9/29/2009 8:02:50 AM
|
|
jacob navia wrote:
> christian.bau a �crit :
>> Just saying that the ability to change an object from being read-only
>> to being modifiable makes some very important optimisations (like very
>> fast copying) impossible. Read up on Apple's Core Foundation library
>> (which is in actual use by a significant number of users).
>
>
> How do you destroy a read-only object?
Read-only is not the same as indestructible. Consider that a programme
may create lots of readonly objects when it is initialised and delete
them all when it terminates.
Also, what is the scope of something like
void test()
{
{
const int i=5;
}
}
> I do not see how you could initially add objects to a read only
> list.
perhaps something like
const int mylist[]={4,6,7,54};
--
Mark McIntyre
CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
|
|
0
|
|
|
|
Reply
|
markmcintyre2 (407)
|
9/29/2009 10:20:16 PM
|
|
Mark McIntyre a �crit :
> jacob navia wrote:
>> christian.bau a �crit :
>>> Just saying that the ability to change an object from being read-only
>>> to being modifiable makes some very important optimisations (like very
>>> fast copying) impossible. Read up on Apple's Core Foundation library
>>> (which is in actual use by a significant number of users).
>>
>>
>> How do you destroy a read-only object?
>
> Read-only is not the same as indestructible. Consider that a programme
> may create lots of readonly objects when it is initialised and delete
> them all when it terminates.
>
> Also, what is the scope of something like
>
> void test()
> {
> {
> const int i=5;
> }
> }
>
Sure, the storage of i goes away but no explicit destruction is done.
For a list, you should free the storage when you destroy it and that
needs a call to free(). Only writable lists can be destroyed, so it is
not possible to destroy a read only list
>> I do not see how you could initially add objects to a read only
>> list.
>
> perhaps something like
>
> const int mylist[]={4,6,7,54};
>
That is an array, not a list. Arrays are supported by the language
natively, and that is not the case for lists.
|
|
0
|
|
|
|
Reply
|
jacob24 (973)
|
9/29/2009 10:34:17 PM
|
|
jacob navia <jacob@nospam.org> writes:
[...]
> Sure, the storage of i goes away but no explicit destruction is done.
> For a list, you should free the storage when you destroy it and that
> needs a call to free(). Only writable lists can be destroyed, so it is
> not possible to destroy a read only list
[...]
It depends on how your list is implemented. If a list object
contains pointers to other data, that other data can be modified
(destroyed, whatever) without modifying the list object itself.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|
0
|
|
|
|
Reply
|
kst-u (21477)
|
9/29/2009 11:11:29 PM
|
|
jacob navia wrote:
> Mark McIntyre a �crit :
>> jacob navia wrote:
>>>
>>> How do you destroy a read-only object?
>>
>> Read-only is not the same as indestructible. Consider that a programme
>> may create lots of readonly objects when it is initialised and delete
>> them all when it terminates.
>>
>> Also, what is the scope of something like
>>
>> void test()
>> {
>> {
>> const int i=5;
>> }
>> }
>>
>
> Sure, the storage of i goes away but no explicit destruction is done.
It is destroyed, and is thus an example of gow a read-only object is
destroyed. And from a purely pedantic point of view, I explicitly caused
it to be destroyed by typing the scope-ending brace.
>>> I do not see how you could initially add objects to a read only
>>> list.
>>
>> perhaps something like
>>
>> const int mylist[]={4,6,7,54};
>
> That is an array, not a list. Arrays are supported by the language
> natively, and that is not the case for lists.
I assume you don't understand the english phrase "something like".
|
|
0
|
|
|
|
Reply
|
markmcintyre2 (407)
|
9/30/2009 8:50:02 PM
|
|
Mark McIntyre <markmcintyre@TROUSERSspamcop.net> writes:
> jacob navia wrote:
>> Mark McIntyre a �crit :
>>> jacob navia wrote:
>>>>
>>>> How do you destroy a read-only object?
>>>
>>> Read-only is not the same as indestructible. Consider that a programme
>>> may create lots of readonly objects when it is initialised and delete
>>> them all when it terminates.
>>>
>>> Also, what is the scope of something like
>>>
>>> void test()
>>> {
>>> {
>>> const int i=5;
>>> }
>>> }
>>>
>>
>> Sure, the storage of i goes away but no explicit destruction is done.
>
> It is destroyed, and is thus an example of gow a read-only object is
> destroyed. And from a purely pedantic point of view, I explicitly caused
> it to be destroyed by typing the scope-ending brace.
lol. Unbelievable. Still arguing and being pedantic with someone who
knows C pretty well.
>
>>>> I do not see how you could initially add objects to a read only
>>>> list.
>>>
>>> perhaps something like
>>>
>>> const int mylist[]={4,6,7,54};
>>
>> That is an array, not a list. Arrays are supported by the language
>> natively, and that is not the case for lists.
>
> I assume you don't understand the english phrase "something like".
>
This is c.l.c You felt the need to explain how you destroyed the object
i by scope ending .....
--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c
|
|
0
|
|
|
|
Reply
|
rgrdev_ (1087)
|
9/30/2009 8:52:00 PM
|
|
Mark McIntyre <markmcintyre@TROUSERSspamcop.net> writes:
> jacob navia wrote:
>> Mark McIntyre a écrit :
>>> jacob navia wrote:
>>>>
>>>> How do you destroy a read-only object?
>>>
>>> Read-only is not the same as indestructible. Consider that a
>>> programme may create lots of readonly objects when it is
>>> initialised and delete them all when it terminates.
>>>
>>> Also, what is the scope of something like
>>>
>>> void test()
>>> {
>>> {
>>> const int i=5;
>>> }
>>> }
>>>
>>
>> Sure, the storage of i goes away but no explicit destruction is done.
>
> It is destroyed, and is thus an example of gow a read-only object is
> destroyed. And from a purely pedantic point of view, I explicitly
> caused it to be destroyed by typing the scope-ending brace.
>
>>>> I do not see how you could initially add objects to a read only
>>>> list.
>>>
>>> perhaps something like
>>>
>>> const int mylist[]={4,6,7,54};
>>
>> That is an array, not a list. Arrays are supported by the language
>> natively, and that is not the case for lists.
>
> I assume you don't understand the english phrase "something like".
And an array can validly be considered a list. To me a (finite)
list is a bijection between an initial subset of the natural numbers
(the validity of 0 in that deliberately being left ambiguous) and
a target set. An array satisfies that definition trivially, and if
you're Bourbaki and programming C, you even get the indices to match.
Phil
--
Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
|
|
0
|
|
|
|
Reply
|
thefatphil_demunged (1558)
|
9/30/2009 9:14:18 PM
|
|
>>>>> "jn" == jacob navia <jacob@nospam.org> writes:
jn> christian.bau a écrit :
>> Just saying that the ability to change an object from being
>> read-only to being modifiable makes some very important
>> optimisations (like very fast copying) impossible. Read up on
>> Apple's Core Foundation library (which is in actual use by a
>> significant number of users).
jn> How do you destroy a read-only object?
jn> You *must* change it to read/write!
Actually, no. In CoreFoundation, you can create and destroy immutable
objects -- you just can't change what they contain.
jn> I do not see how you could initially add objects to a read only
jn> list. You *have* to get rid of the read-only flag when
jn> initializing and when destroying the object.
You have a limited notion of "read-only" that is not shared by all
library authors.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
|
|
0
|
|
|
|
Reply
|
cwilbur2 (385)
|
9/30/2009 9:29:45 PM
|
|
Charlton Wilbur a écrit :
>>>>>> "jn" == jacob navia <jacob@nospam.org> writes:
>
> jn> christian.bau a écrit :
>
> >> Just saying that the ability to change an object from being
> >> read-only to being modifiable makes some very important
> >> optimisations (like very fast copying) impossible. Read up on
> >> Apple's Core Foundation library (which is in actual use by a
> >> significant number of users).
>
> jn> How do you destroy a read-only object?
>
> jn> You *must* change it to read/write!
>
> Actually, no. In CoreFoundation, you can create and destroy immutable
> objects -- you just can't change what they contain.
>
> jn> I do not see how you could initially add objects to a read only
> jn> list. You *have* to get rid of the read-only flag when
> jn> initializing and when destroying the object.
>
> You have a limited notion of "read-only" that is not shared by all
> library authors.
>
> Charlton
>
>
The Apple libraries say that to create an immutable object (read only)
you should initialize it with a C array. Then, obviously, you can't
create any immutable object that contains an heterogeneous set of object
that will never fit in a C array.
Another limitation of the Apple design is that you can't change the immutable
property after the container is created. In my design that is possible.
(At least I did not find how, maybe I am wrong in this respect).
It is pointless to argue about this or that characteristic of the sample
implementation that I provide. It doesn't matter since you can create your
own implementation (that could mimic Apple's design) at will. What I am
proposing is an INTERFACE, and providing a sample implementation to
demonstrate how an implementation *could* be done. The INTERFACE is the only
fixed part of this stuff. I provide the sample implementation to make it
easy to implement different "flavors" of the INTERFACE.
But please do not consider the sample implementation as the only way to
implement the interface.
There will never be a single library that will satisfy ALL needs. What
do you need is a common interface that allows you to switch from one
implementation to another without changing a single line in your source
code.
|
|
0
|
|
|
|
Reply
|
jacob24 (973)
|
9/30/2009 10:56:19 PM
|
|
>>>>> "jn" == jacob navia <jacob@nospam.org> writes:
>> You have a limited notion of "read-only" that is not shared by
>> all library authors.
jn> The Apple libraries say that to create an immutable object (read
jn> only) you should initialize it with a C array. Then, obviously,
jn> you can't create any immutable object that contains an
jn> heterogeneous set of object that will never fit in a C array.
Except that, oddly enough, they do, because CoreFoundation provides
containers for just such a purpose!
jn> Another limitation of the Apple design is that you can't change
jn> the immutable property after the container is created. In my
jn> design that is possible. (At least I did not find how, maybe I
jn> am wrong in this respect).
Of course you can't change it - it's *immutable*. You get significant
performance benefits from that. If you want to change it, you make a
mutable copy of it.
jn> But please do not consider the sample implementation as the only
jn> way to implement the interface.
I haven't even looked at your implementation. I was commenting on the
way you seem to think your approach is the only correct one, and that
you seem unwilling or unable to even attempt to understand other
approaches.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
|
|
0
|
|
|
|
Reply
|
cwilbur2 (385)
|
10/1/2009 2:16:01 PM
|
|
Charlton Wilbur a �crit :
> I haven't even looked at your implementation.
Sure sure. Then, you write the following sentence:
> I was commenting on the
> way you seem to think your approach is the only correct one, and that
> you seem unwilling or unable to even attempt to understand other
> approaches.
>
So, you do not even look at what I am proposing, then, you snip
the paragraph where I say explicitly that the sample implementation
is just ONE way of implementing the interface, designed to
easy the customization and THEN
of course you accuse me of ignoring other implementations...
After you quoted my comments concerning Apple's implementation...
OK.
|
|
0
|
|
|
|
Reply
|
jacob24 (973)
|
10/1/2009 2:26:37 PM
|
|
jacob navia wrote:
> Charlton Wilbur a �crit :
>> I haven't even looked at your implementation.
>
> Sure sure. Then, you write the following sentence:
>
>> I was commenting on the
>> way you seem to think your approach is the only correct one, and that
>> you seem unwilling or unable to even attempt to understand other
>> approaches.
>>
>
> So, you do not even look at what I am proposing,
Its not relevant since his point was concerning your attitude to
alternative approaches.
> of course you accuse me of ignoring other implementations...
> After you quoted my comments concerning Apple's implementation...
No, he "accused" you of apparently thinking yours was the only correct
one, to the extent of being unable or unwilling to even attempt to
understand the alternatives. I don't think your comments on Apple's
approach contradict that suggestion.
Why do you always, always, assume any criticism is a personal attack?
--
Mark McIntyre
CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
|
|
0
|
|
|
|
Reply
|
markmcintyre2 (407)
|
10/1/2009 7:00:59 PM
|
|
|
16 Replies
32 Views
(page loaded in 0.222 seconds)
Similiar Articles: lcc-win32 sources - comp.compilers.lccUpdates to lcc-win32 - comp.compilers.lcc A container library for C - comp.compilers.lcc lcc ... Where can I download winbase.h ? - comp.compilers.lcc:) For the most part ... comp.std.c++ - page 2... be coded in place of the "/*What goes here*/" part? ... assign members 2 43 (11/20/2009 1:18:00 AM) The container ... 11/18/2009 8:32:06 PM) Currently, the draft C++0x library ... comp.lang.c++.moderated - page 7... to the begin and end of a container ... is used by the 'function' library from boost which has recently been adopted as part ... that I hide behind a c-api inside a library ... Connecting to Filemaker with asp.net - comp.databases.filemaker ...Hi, Does anyone know if there is a library that connects ... mail me at pit@NOSPAM.nlr.nl ( remove the NOSPAM part ... ODBC: Howto access container fields? - comp.databases ... Should I use C++ or Java for Numeric Intensive Calculations - comp ...By using non-standard libraries, both languages could get ... For my part, the most significant difference between ... Linking vs. embeding files in container fields - comp ... How to simulate variadic templates? - comp.lang.c++.moderated ...... is to store arguments into a etherogenous container like ... but for now I'd recommend using boost::forward library ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp ... Generating excel sheets through JSP - comp.lang.java.programmer ...Thompson, JSTL provides library tags to ... catch var=3D"sampleExc"> - code - </c:catch> By this JSP container ... JSP code ... </c:catch> <c:if test="${e ... Const constructor - comp.lang.c++.moderatedThat's why iterator and const_iterator of containers are ... features below. const int const_vec[] = { 1, 2, 3, 4 ... I agree const issues are some of the developing parts of ... writing robust software? - comp.lang.c++.moderatedI think I have already bad memory leaks, when I some parts of m= y ... top of the usual std::bad_alloc throwing copy constructors the standard library containers ... Swing Copy Problem - comp.lang.java.gui//***** // public Container createContentPane() { //Create the content ... for Copy and Paste | eHow.com The Swing user interface library that comes as a standard part of the ... Why am I getting a remainder when calculating date difference ...... have heard of a JavaScript using a UNIX or Linux library ... choice of Time Zone - with exceptions for parts of ... add - comp.lang.java.gui So why is java.awt.Container ... Collection Classes (C#) - Microsoft Corporation: Software ...MSDN Library ... Collection classes are defined as part of the System ... ArrayList Names = new ArrayList(); ... ArrayList Class (System.Collections) - Microsoft Corporation ...... Using a Web Deployment Package (Part 1 of 4) ... http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx.EXAMPLE PSH [C:\foo]: .\Get-ArrayList.ps1 7/29/2012 6:54:15 AM
|