Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Ahead warp factor 1" -- Captain Kirk


devel / comp.lang.c / something about array of various subtypes

SubjectAuthor
* something about array of various subtypesfir
`* Re: something about array of various subtypesfir
 `* Re: something about array of various subtypesfir
  +- Re: something about array of various subtypesfir
  `- Re: something about array of various subtypesfir

1
something about array of various subtypes

<b0cdfcce-41bd-4f30-8feb-2bc23ff84d3dn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26986&group=comp.lang.c#26986

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:181c:b0:403:fe96:5779 with SMTP id t28-20020a05622a181c00b00403fe965779mr4608qtc.5.1691143660131;
Fri, 04 Aug 2023 03:07:40 -0700 (PDT)
X-Received: by 2002:a05:6808:1927:b0:3a7:45f6:4b3f with SMTP id
bf39-20020a056808192700b003a745f64b3fmr1900161oib.3.1691143659854; Fri, 04
Aug 2023 03:07:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 4 Aug 2023 03:07:39 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.150; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.150
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b0cdfcce-41bd-4f30-8feb-2bc23ff84d3dn@googlegroups.com>
Subject: something about array of various subtypes
From: profesor...@gmail.com (fir)
Injection-Date: Fri, 04 Aug 2023 10:07:40 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1819
 by: fir - Fri, 4 Aug 2023 10:07 UTC

i once was writing here my new observation
sometimes you need an array of things that
have some general type but differ on subtyopes

in c you would put that subtype as an enum signature
and put it all as record of arrays eventually
having union part

in c++ you use inheritance and virtual function

my thought was both are maybe bad as whot you
could do is to put it in two dimensional
array where this enum tag is a second rank
index

if you use such two dimensional you probably
also can sorta spare of unions as with 2-dimensional
array you get option to attach various size arrays
under that so same size is not strictly needed

its kinda interesting thought that both c popular
approach and c++ one are wrong

the question is hovever 1) how it can be exactly done
2) if language could support it more

Re: something about array of various subtypes

<fc66c2f9-5055-4038-8be4-427b36201fa7n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=26991&group=comp.lang.c#26991

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:6a85:b0:76c:daf4:2787 with SMTP id ud5-20020a05620a6a8500b0076cdaf42787mr3551qkn.4.1691148062598;
Fri, 04 Aug 2023 04:21:02 -0700 (PDT)
X-Received: by 2002:a05:6870:3a06:b0:1bb:4707:9b4a with SMTP id
du6-20020a0568703a0600b001bb47079b4amr1424830oab.5.1691148062352; Fri, 04 Aug
2023 04:21:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 4 Aug 2023 04:21:01 -0700 (PDT)
In-Reply-To: <b0cdfcce-41bd-4f30-8feb-2bc23ff84d3dn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.193; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.193
References: <b0cdfcce-41bd-4f30-8feb-2bc23ff84d3dn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fc66c2f9-5055-4038-8be4-427b36201fa7n@googlegroups.com>
Subject: Re: something about array of various subtypes
From: profesor...@gmail.com (fir)
Injection-Date: Fri, 04 Aug 2023 11:21:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2648
 by: fir - Fri, 4 Aug 2023 11:21 UTC

piątek, 4 sierpnia 2023 o 12:07:48 UTC+2 fir napisał(a):
> i once was writing here my new observation
> sometimes you need an array of things that
> have some general type but differ on subtyopes
>
> in c you would put that subtype as an enum signature
> and put it all as record of arrays eventually
> having union part
>
> in c++ you use inheritance and virtual function
>
> my thought was both are maybe bad as whot you
> could do is to put it in two dimensional
> array where this enum tag is a second rank
> index
>
> if you use such two dimensional you probably
> also can sorta spare of unions as with 2-dimensional
> array you get option to attach various size arrays
> under that so same size is not strictly needed
>
> its kinda interesting thought that both c popular
> approach and c++ one are wrong
>
> the question is hovever 1) how it can be exactly done
> 2) if language could support it more

those low lewel/deep c ideas (like those rellocked containers, splitter
for chunks etc, but also how stack works etc, something that just need
strong logic ) i could call 'hard c'

if in co someone learns how to use some concepts in c c is easy liek
a pice of cace but there are regions of hard c where for some time you could
bump your head in a wall (if youre a noob) or just isolate and get think
(where youre more experienced)

Re: something about array of various subtypes

<eb5b912e-92f5-40b1-9249-981611c18a55n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27018&group=comp.lang.c#27018

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:58c5:0:b0:76c:69ac:a0f0 with SMTP id m188-20020a3758c5000000b0076c69aca0f0mr6345qkb.4.1691168538702;
Fri, 04 Aug 2023 10:02:18 -0700 (PDT)
X-Received: by 2002:a05:6870:5b18:b0:1bf:9214:1fd5 with SMTP id
ds24-20020a0568705b1800b001bf92141fd5mr2260098oab.1.1691168538402; Fri, 04
Aug 2023 10:02:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 4 Aug 2023 10:02:17 -0700 (PDT)
In-Reply-To: <fc66c2f9-5055-4038-8be4-427b36201fa7n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.71; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.71
References: <b0cdfcce-41bd-4f30-8feb-2bc23ff84d3dn@googlegroups.com> <fc66c2f9-5055-4038-8be4-427b36201fa7n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eb5b912e-92f5-40b1-9249-981611c18a55n@googlegroups.com>
Subject: Re: something about array of various subtypes
From: profesor...@gmail.com (fir)
Injection-Date: Fri, 04 Aug 2023 17:02:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5497
 by: fir - Fri, 4 Aug 2023 17:02 UTC

piątek, 4 sierpnia 2023 o 13:21:11 UTC+2 fir napisał(a):
> piątek, 4 sierpnia 2023 o 12:07:48 UTC+2 fir napisał(a):
> > i once was writing here my new observation
> > sometimes you need an array of things that
> > have some general type but differ on subtyopes
> >
> > in c you would put that subtype as an enum signature
> > and put it all as record of arrays eventually
> > having union part
> >
> > in c++ you use inheritance and virtual function
> >
> > my thought was both are maybe bad as whot you
> > could do is to put it in two dimensional
> > array where this enum tag is a second rank
> > index
> >
> > if you use such two dimensional you probably
> > also can sorta spare of unions as with 2-dimensional
> > array you get option to attach various size arrays
> > under that so same size is not strictly needed
> >
> > its kinda interesting thought that both c popular
> > approach and c++ one are wrong
> >
> > the question is hovever 1) how it can be exactly done
> > 2) if language could support it more

i made soem exeprimentation .. this below is code for this container
(i named it vac from variants container)..teh advantage is you
can put any sized tagged ('signatured') structures into it
and they will be kept together by types, its 2x reallocable
- the main vector (name it temporarely a vector though should name
it array) keeps types and each have inner vector (i eventually should
change names as i mix 'types' names with 'variants'

disadvantage is maybe this loop iteration and acces via small inline helping functions though its probably to learn (maybe liek chunks, the chunks i liked and lerned was no problem with that)

here below i make brutal cast but is becouse i wanted to show some can
some may also use the iff acces by type, or use only one type of
physical record but use tags to sort it by content and 'logical' meaning
(phisical layout stay the same for optimistaion)

logicallly this conception is good imo as its better then puting things all to 1dimensional table, here acces by groups is granted so some codes liek colision
interactions not need to saw thru wasted empty loops

// vac = variants container

struct VacEntry { int type; int size; void* tab; int tab_size; };

VacEntry* vac = NULL; int types = 0;

int FindOrCreateVarArray(int type)
{ for(int i=0; i<types; i++)
if( vac[i].type == type ) return i;

types++;
vac = (VacEntry*) realloc(vac, sizeof(VacEntry)*types );
vac[types-1] = {type, 0, NULL, 0};

return types-1;
}

int AddVacVariant(int variant_type, void* variant, int variant_size)
{ int s = FindOrCreateVarArray(variant_type);
vac[s].tab_size++;
vac[s].size= variant_size;
vac[s].tab = realloc(vac[s].tab, vac[s].tab_size*vac[s].size);
int n = vac[s].tab_size-1;
void* var_adress = (char*)(vac[s].tab) + n*vac[s].size;
memcpy(var_adress, variant, variant_size);
}

inline void* vac_element(int s, int i){ return (vac[s].tab + i*vac[s].size);}
inline int vac_type(int s){ return vac[s].type;}
inline int vac_siz(int s){ return vac[s].tab_size;}

struct Human {char* name; float x,y,HP;};
struct Alien {char* name; float x,y,HP, a,b,c;};

void PrintAgentsCOmmonInfo()
{ for(int s=0; s<types;s++)
{
int type = vac_type(s);
int n = vac_siz(s);
for(int i=0; i<n; i++)
{
Human* h = (Human*) vac_element(s,i);
printf("\n name %s, HP %f ", (*h).name, (*h).HP);
}

}

}

void TestVac()
{

Human adam = {"adam", 0,0,100};
Human beata = {"beata", 100,100,200};
Human chloe = {"chloae", 20,20,79};
Alien zzxzz = {"zzxzz", 0,0,100,1,1,1};
Alien ssyss = {"ssyss", 100,100,200,2,2,2};
Alien bbnbb = {"bbnbb", 20,20,79,3,3,3};
AddVacVariant('hum', &adam, sizeof(Human));
AddVacVariant('ali', &zzxzz, sizeof(Human));
AddVacVariant('ali', &ssyss, sizeof(Human));
AddVacVariant('ali', &bbnbb, sizeof(Human));
AddVacVariant('hum', &beata, sizeof(Human));
AddVacVariant('hum', &chloe, sizeof(Human));

PrintAgentsCOmmonInfo();
}

Re: something about array of various subtypes

<9c14554a-a4d2-4240-8771-d83fa972bb4fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27021&group=comp.lang.c#27021

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a0c:fe0e:0:b0:63d:922:57a2 with SMTP id x14-20020a0cfe0e000000b0063d092257a2mr991qvr.6.1691168961239;
Fri, 04 Aug 2023 10:09:21 -0700 (PDT)
X-Received: by 2002:a05:6808:1789:b0:3a7:62f7:9c48 with SMTP id
bg9-20020a056808178900b003a762f79c48mr3139844oib.11.1691168960852; Fri, 04
Aug 2023 10:09:20 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 4 Aug 2023 10:09:20 -0700 (PDT)
In-Reply-To: <eb5b912e-92f5-40b1-9249-981611c18a55n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.71; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.71
References: <b0cdfcce-41bd-4f30-8feb-2bc23ff84d3dn@googlegroups.com>
<fc66c2f9-5055-4038-8be4-427b36201fa7n@googlegroups.com> <eb5b912e-92f5-40b1-9249-981611c18a55n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9c14554a-a4d2-4240-8771-d83fa972bb4fn@googlegroups.com>
Subject: Re: something about array of various subtypes
From: profesor...@gmail.com (fir)
Injection-Date: Fri, 04 Aug 2023 17:09:21 +0000
Content-Type: text/plain; charset="UTF-8"
 by: fir - Fri, 4 Aug 2023 17:09 UTC

> AddVacVariant('hum', &adam, sizeof(Human));
> AddVacVariant('ali', &zzxzz, sizeof(Human));
> AddVacVariant('ali', &ssyss, sizeof(Human));
> AddVacVariant('ali', &bbnbb, sizeof(Human));
> AddVacVariant('hum', &beata, sizeof(Human));
> AddVacVariant('hum', &chloe, sizeof(Human));
>

typos above should be

AddVacVariant('hum', &adam, sizeof(Human));
AddVacVariant('ali', &zzxzz, sizeof(Alien));
AddVacVariant('ali', &ssyss, sizeof(Alien));
AddVacVariant('ali', &bbnbb, sizeof(Alien));
AddVacVariant('hum', &beata, sizeof(Human));
AddVacVariant('hum', &chloe, sizeof(Human));

Re: something about array of various subtypes

<ab700a97-bbc0-4a46-9b5c-8e50e81e664fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27022&group=comp.lang.c#27022

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1a08:b0:40c:84bb:1b09 with SMTP id f8-20020a05622a1a0800b0040c84bb1b09mr2007qtb.0.1691169514923;
Fri, 04 Aug 2023 10:18:34 -0700 (PDT)
X-Received: by 2002:a05:6870:5b10:b0:1bb:4593:edfb with SMTP id
ds16-20020a0568705b1000b001bb4593edfbmr2123476oab.1.1691169514469; Fri, 04
Aug 2023 10:18:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 4 Aug 2023 10:18:34 -0700 (PDT)
In-Reply-To: <eb5b912e-92f5-40b1-9249-981611c18a55n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.71; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.71
References: <b0cdfcce-41bd-4f30-8feb-2bc23ff84d3dn@googlegroups.com>
<fc66c2f9-5055-4038-8be4-427b36201fa7n@googlegroups.com> <eb5b912e-92f5-40b1-9249-981611c18a55n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ab700a97-bbc0-4a46-9b5c-8e50e81e664fn@googlegroups.com>
Subject: Re: something about array of various subtypes
From: profesor...@gmail.com (fir)
Injection-Date: Fri, 04 Aug 2023 17:18:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4562
 by: fir - Fri, 4 Aug 2023 17:18 UTC

piątek, 4 sierpnia 2023 o 19:02:26 UTC+2 fir napisał(a):
> piątek, 4 sierpnia 2023 o 13:21:11 UTC+2 fir napisał(a):
> > piątek, 4 sierpnia 2023 o 12:07:48 UTC+2 fir napisał(a):
> > > i once was writing here my new observation
> > > sometimes you need an array of things that
> > > have some general type but differ on subtyopes
> > >
> > > in c you would put that subtype as an enum signature
> > > and put it all as record of arrays eventually
> > > having union part
> > >
> > > in c++ you use inheritance and virtual function
> > >
> > > my thought was both are maybe bad as whot you
> > > could do is to put it in two dimensional
> > > array where this enum tag is a second rank
> > > index
> > >
> > > if you use such two dimensional you probably
> > > also can sorta spare of unions as with 2-dimensional
> > > array you get option to attach various size arrays
> > > under that so same size is not strictly needed
> > >
> > > its kinda interesting thought that both c popular
> > > approach and c++ one are wrong
> > >
> > > the question is hovever 1) how it can be exactly done
> > > 2) if language could support it more
> i made soem exeprimentation .. this below is code for this container
> (i named it vac from variants container)..teh advantage is you
> can put any sized tagged ('signatured') structures into it
> and they will be kept together by types, its 2x reallocable
> - the main vector (name it temporarely a vector though should name
> it array) keeps types and each have inner vector (i eventually should
> change names as i mix 'types' names with 'variants'
>
> disadvantage is maybe this loop iteration and acces via small inline helping functions though its probably to learn (maybe liek chunks, the chunks i liked and lerned was no problem with that)
>
> here below i make brutal cast but is becouse i wanted to show some can
> some may also use the iff acces by type, or use only one type of
> physical record but use tags to sort it by content and 'logical' meaning
> (phisical layout stay the same for optimistaion)
>
> logicallly this conception is good imo as its better then puting things all to 1dimensional table, here acces by groups is granted so some codes liek colision
> interactions not need to saw thru wasted empty loops
>
>
> // vac = variants container
>

possibly in other alnguages this is called dictionary or something
here it is resizable array of signatured resizable arrays of various type..
on c ground such dictionarry is something other as it is kinda low lewel dictionary and some internals show - for example its seen that those signatures (keys) be better integer normal ordinal values (enums) to speed things up..there also
options to make it half static or fully static for execution speed (yawn)

i will rather stay with dynamic version unles maybe i wil be writing something time critical and then i would measure times (but recently i overally not write to much)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor