From: Alexey Tourbin <alexey.tourbin@gmail.com>
To: ALT Linux Team development discussions <devel@lists.altlinux.org>
Subject: Re: [devel] Утилиты для работы с setversions?
Date: Sun, 27 Oct 2019 01:38:40 +0300
Message-ID: <CA+qzennqqN-PLV-HXmkE7sG02ds3-cqfDfKxSPa5YqXoFuqfGA@mail.gmail.com> (raw)
In-Reply-To: <20191026181016.513833b24496528e56d4899d@altlinux.org>
[-- Attachment #1: Type: text/plain, Size: 1197 bytes --]
On Sat, Oct 26, 2019 at 6:10 PM Andrey Savchenko <bircoph@altlinux.org> wrote:
> On Sat, 26 Oct 2019 17:17:25 +0300 Alexey Tourbin wrote:
> > $ rpm -q --provides glibc-core |grep 'libdl.*set'
> > libdl.so.2()(64bit) = set:hdBjS1I4gQ8BohwImELo8Zh
> > $ ./a.out set:hdBjS1I4gQ8BohwImELo8Zh
> > 0272
> > 0a8f
> > 12b4
> > 1f1c
> > 1fb0
> > 23f5
> > 31a1
> > 3571
> > 35d3
> > 3bcb
>
> Как я понял, это хеши символов. По какому алгоритму они вычисляются?
> Мне нужно для имеющегося списка символов вычислить аналогичные хеши
> для дальнейшего сравнения.
Это set.c:hash(), но можно воспользоваться set_new/set_add, который
хеширует и сортирует строки по хешу. Прикрепил более полный пример.
$ /usr/lib/rpm/provided_symbols /lib64/libdl.so.2 |./a.out
set:hdBjS1I4gQ8BohwImELo8Zh 1
0272 dladdr1
0a8f _dlfcn_hook
12b4 dlsym
1f1c dlerror
1fb0 dlclose
23f5 dlopen
31a1 dlinfo
3571 dlvsym
35d3 dladdr
3bcb dlmopen
[-- Attachment #2: printset.c --]
[-- Type: text/x-csrc, Size: 1184 bytes --]
#include <stdio.h>
#include "set.c"
int main(int argc, char **argv)
{
assert(argc == 2);
const char *s = argv[1];
assert(strncmp(s, "set:", 4) == 0);
s += 4;
int bpp, m;
int rc = decode_set_init(s, &bpp, &m);
assert(rc == 0);
size_t len = strlen(s);
int n = decode_set_size(len, m);
assert(n > 0);
unsigned v[n];
n = decode_set(s, m, v);
assert(n > 0);
// Read the list of symbols from stdin.
struct set *set = set_new();
char *line = NULL;
size_t alloc = 0;
while ((len = getline(&line, &alloc, stdin)) != -1) {
assert(len > 1);
len--;
assert(line[len] == '\n');
line[len] = '\0';
set_add(set, line);
}
// Hash and sort the symbols by hash.
s = set_fini(set, bpp);
assert(s && "non-empty set");
s = _free(s); // don't neeed the result, only the internal structure
// Join v[] and set->sv[].
int w = (bpp + 3) / 4;
for (int i = 0; i < n; i++) {
// TODO: handle collisions and/or missing elements,
// advance lists separately like in mergesort.
assert(set->sv[i].v == v[i]);
printf("%0*x %s\n", w, v[i], set->sv[i].s);
}
set_free(set);
return 0;
}
next prev parent reply other threads:[~2019-10-26 22:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-26 13:31 Andrey Savchenko
2019-10-26 14:17 ` Alexey Tourbin
2019-10-26 15:10 ` Andrey Savchenko
2019-10-26 22:38 ` Alexey Tourbin [this message]
2019-10-26 22:47 ` Andrey Savchenko
2019-10-29 18:23 ` Andrey Savchenko
2019-10-30 2:04 ` Alexey Tourbin
2019-10-30 9:06 ` Andrey Savchenko
2019-10-30 10:46 ` Vladimir D. Seleznev
2019-10-30 11:38 ` Andrey Savchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA+qzennqqN-PLV-HXmkE7sG02ds3-cqfDfKxSPa5YqXoFuqfGA@mail.gmail.com \
--to=alexey.tourbin@gmail.com \
--cc=devel@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git