Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

What the world *really* needs is a good Automatic Bicycle Sharpener.


devel / comp.lang.c / Re: interesying case of fir's c dictionary

SubjectAuthor
* interesying case of fir's c dictionaryfir
`* Re: interesying case of fir's c dictionaryfir
 `- Re: interesying case of fir's c dictionaryfir

1
interesying case of fir's c dictionary

<f683ace6-fa04-4d46-b495-fbbaa091c4c8n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:199f:b0:767:dd55:2add with SMTP id bm31-20020a05620a199f00b00767dd552addmr16400qkb.14.1691266311362;
Sat, 05 Aug 2023 13:11:51 -0700 (PDT)
X-Received: by 2002:a05:6870:3308:b0:1be:d373:4cd with SMTP id
x8-20020a056870330800b001bed37304cdmr5131624oae.5.1691266311142; Sat, 05 Aug
2023 13:11:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.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: Sat, 5 Aug 2023 13:11:50 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.205; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.205
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f683ace6-fa04-4d46-b495-fbbaa091c4c8n@googlegroups.com>
Subject: interesying case of fir's c dictionary
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 05 Aug 2023 20:11:51 +0000
Content-Type: text/plain; charset="UTF-8"
 by: fir - Sat, 5 Aug 2023 20:11 UTC

in seoparate thread i wrote my thoughts about how
how some things (i mean managng array of variants of
some entites) should be done and it led me to
a two dimensuonal array where the second dimension is
tag-signature...and this is in fact what is so called dictionary

i wrote this (though not tested to much) ..i wonder how people
write analogon of such dictionaries in c, they must use something but i
dont know what so im not able to say what thsi i wrote si oryginal
but possibly find it natbe somewhat oryginal

heres the whole dictionary code :

struct Dict_KeyEntry { int key; int el_size; void* tab; int slen; };
Dict_KeyEntry* dict = NULL; int dict_keys = 0;

int dict_Add(int key, void* el, int el_size)
{ find_key: int k; for(k=0; k<dict_keys; k++) if( dict[k].key == key ) goto upsize_tab ;
upsize_keys: dict = (Dict_KeyEntry*) realloc(dict, ++dict_keys*sizeof(Dict_KeyEntry) );
dict[k] = {key, el_size, NULL, 0};
upsize_tab: dict[k].tab = realloc(dict[k].tab, ++dict[k].slen * dict[k].el_size);
insert_element: memcpy((char*)(dict[k].tab)+(dict[k].slen-1)*dict[k].el_size, el, el_size);
}

inline void* dict_el(int s, int i) {return (dict[s].tab + i*dict[s].el_size);}

Re: interesying case of fir's c dictionary

<b319fc38-4ba1-4858-bd5e-3a5fc8216ef3n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:4b74:0:b0:63f:7a4f:9186 with SMTP id m20-20020ad44b74000000b0063f7a4f9186mr8254qvx.0.1691267662574;
Sat, 05 Aug 2023 13:34:22 -0700 (PDT)
X-Received: by 2002:a05:6808:20a4:b0:3a7:538b:b673 with SMTP id
s36-20020a05680820a400b003a7538bb673mr8821301oiw.3.1691267662182; Sat, 05 Aug
2023 13:34:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!3.us.feeder.erje.net!feeder.erje.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 5 Aug 2023 13:34:21 -0700 (PDT)
In-Reply-To: <f683ace6-fa04-4d46-b495-fbbaa091c4c8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.212; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.212
References: <f683ace6-fa04-4d46-b495-fbbaa091c4c8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b319fc38-4ba1-4858-bd5e-3a5fc8216ef3n@googlegroups.com>
Subject: Re: interesying case of fir's c dictionary
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 05 Aug 2023 20:34:22 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 94
 by: fir - Sat, 5 Aug 2023 20:34 UTC

sobota, 5 sierpnia 2023 o 22:12:01 UTC+2 fir napisał(a):
> in seoparate thread i wrote my thoughts about how
> how some things (i mean managng array of variants of
> some entites) should be done and it led me to
> a two dimensuonal array where the second dimension is
> tag-signature...and this is in fact what is so called dictionary
>
> i wrote this (though not tested to much) ..i wonder how people
> write analogon of such dictionaries in c, they must use something but i
> dont know what so im not able to say what thsi i wrote si oryginal
> but possibly find it natbe somewhat oryginal
>
> heres the whole dictionary code :
>
> struct Dict_KeyEntry { int key; int el_size; void* tab; int slen; };
> Dict_KeyEntry* dict = NULL; int dict_keys = 0;
>
> int dict_Add(int key, void* el, int el_size)
> {
> find_key: int k; for(k=0; k<dict_keys; k++) if( dict[k].key == key ) goto upsize_tab ;
> upsize_keys: dict = (Dict_KeyEntry*) realloc(dict, ++dict_keys*sizeof(Dict_KeyEntry) );
> dict[k] = {key, el_size, NULL, 0};
> upsize_tab: dict[k].tab = realloc(dict[k].tab, ++dict[k].slen * dict[k]..el_size);
> insert_element: memcpy((char*)(dict[k].tab)+(dict[k].slen-1)*dict[k].el_size, el, el_size);
> }
>
> inline void* dict_el(int s, int i) {return (dict[s].tab + i*dict[s].el_size);}

sadly there is some unconvenience of using this but the code above is somewhat curious (curious is its few lines for whole dictionary)

as tu usage inserting is somewhat standable becouse its understandable as i decided to insert by memcopy i need to pass sizeof

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

void TestDictionary()
{

Human adam = {"adam", 100,0,10};
Human beata = {"beata", 200,100,20};
Human chloe = {"chloae",300,30,30};
Alien zzxzz = {"zzxzz", 40,0,44,1,1,1};
Alien ssyss = {"ssyss", 50,100,55,2,2,2};
Alien bbnbb = {"bbnbb", 60,20,66,3,3,3};

dict_Add('human', &adam, sizeof(Human));
dict_Add('alien', &zzxzz, sizeof(Alien));
dict_Add('alien', &ssyss, sizeof(Alien));
dict_Add('alien', &bbnbb, sizeof(Alien));
dict_Add('human', &beata, sizeof(Human));
dict_Add('human', &chloe, sizeof(Human));

extern void PrintOutDictionary(); PrintOutDictionary();
}

more normal would be to comment line with memcopy and write a custom
functions for inserting using args to assign to record fields

acces is imo maybe kinda less standable as you need the function
returnig pointer to element ram..this is becoyse this dictionary holds different size
structures under different keys (there is an option to hold uniwersal one type structure then simply pointer tu subarray can be returned

well here also poiners to subarrays can be returned though it needs
type reckognizing switch

void PrintOutDictionary()
{ for(int s=0; s<dict_keys;s++)
for(int i=0; i<dict[s].slen; i++)
{
Human* h = (Human*) dict_el(s,i);
printf("\n name %s, HP %f ", (*h).name, (*h).HP);
}

}

some notes
1) it may seem to look ugly but in fact when koding such things you need to do such things (like this key-based switch) anyway
2) it shows the lacks of c as if c would be mendad as i propose those things can be both written ad use much nicer

Re: interesying case of fir's c dictionary

<9a0c244e-92fa-46d0-8c45-c03a8edbcc9cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5a53:0:b0:63c:f853:c8f with SMTP id ej19-20020ad45a53000000b0063cf8530c8fmr15326qvb.6.1691274118770;
Sat, 05 Aug 2023 15:21:58 -0700 (PDT)
X-Received: by 2002:a05:6870:7716:b0:1bb:576c:7397 with SMTP id
dw22-20020a056870771600b001bb576c7397mr5890078oab.11.1691274118497; Sat, 05
Aug 2023 15:21:58 -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: Sat, 5 Aug 2023 15:21:58 -0700 (PDT)
In-Reply-To: <b319fc38-4ba1-4858-bd5e-3a5fc8216ef3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.74; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.74
References: <f683ace6-fa04-4d46-b495-fbbaa091c4c8n@googlegroups.com> <b319fc38-4ba1-4858-bd5e-3a5fc8216ef3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9a0c244e-92fa-46d0-8c45-c03a8edbcc9cn@googlegroups.com>
Subject: Re: interesying case of fir's c dictionary
From: profesor...@gmail.com (fir)
Injection-Date: Sat, 05 Aug 2023 22:21:58 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3660
 by: fir - Sat, 5 Aug 2023 22:21 UTC

in reallity with custom add functions it would look nicer fortunatelly

struct Asteroid {float x,y,r, HP;};

void AddAsteroid(float x, float y, float r, float HP)
{ Asteroid* as = (Asteroid*) dict_AddEmpty('asteroid', sizeof(Asteroid));
as[0].x = x;
as[0].y = y;
as[0].r = r;
as[0].HP = HP;

}

struct AlienShip {float x,y,r, speed, HP;};

void AddAlienShip(float x, float y, float r, float speed, float HP)
{ AlienShip* al = (AlienShip*) dict_AddEmpty('alien', sizeof(AlienShip));
al[0].x = x;
al[0].y = y;
al[0].r = r;
al[0].speed =speed;
al[0].HP = HP;
}

void TestDictionary()
{

for(int i=0; i<1000; i++) AddAsteroid(rand2(-1000,1000), rand2(-1000,1000), 10, rand2(60,100));
for(int i=0; i<20; i++) AddAlienShip(rand2(-1000, 1000), rand2(0,1000), 10, rand2(10,12), rand2(20,25));

PrintOutAlienAsteroidCollisions();
} and those functions are needed anyway... this dictionary as it holds main game data dont need to be referenced by name as its just global inviosible container

the code to loop and use them is liek that

void PrintOutAlienAsteroidCollisions()
{ int alien_len, asteroid_len ;

AlienShip* alien = (AlienShip*) dict_Array('alien', &alien_len);
Asteroid* asteroid = (Asteroid*) dict_Array('asteroid', &asteroid_len);

for(int j=0; j<alien_len; j++)
for(int i=0; i<asteroid_len; i++)
{
float dx = alien[j].x - asteroid[i].x;
float dy = alien[j].y - asteroid[i].y;

if(sqrt(dx*dx + dy*dy)< alien[j].r + asteroid[i].r )
printf("\n collision of alien %d with asteroid %d", j,i);
}

}

ehere code for dictionaty

struct Dict_KeyEntry { int key; int el_size; void* tab; int slen; };
Dict_KeyEntry* dict = NULL; int dict_keys = 0;

void* dict_AddEmpty(int key, int el_size)
{ find_key: int k; for(k=0; k<dict_keys; k++) if( dict[k].key == key ) goto upsize_tab ;
upsize_keys: dict = (Dict_KeyEntry*) realloc(dict, ++dict_keys*sizeof(Dict_KeyEntry) );
dict[k] = {key, el_size, NULL, 0};
upsize_tab: dict[k].tab = realloc(dict[k].tab, ++dict[k].slen * dict[k].el_size);
return_adress: return (char*)(dict[k].tab)+(dict[k].slen-1)*dict[k].el_size;
} void* dict_Array(int key, int* len)
{ for(int k=0; k<dict_keys; k++)
if( dict[k].key == key ) { *len = dict[k].slen; return dict[k].tab; }

printf("ERROR (dict_Array): array not found for such key"); exit(-1);
}

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor