<commit_before>#include <assert.h>

//libsolv
#include "solv/evr.h"
#include "solv/pool.h"
#include "solv/repo.h"
#include "solv/util.h"

// hawkey
#include "iutil.h"
#include "package_internal.h"

static Solvable *
get_solvable(HyPackage pkg)
{
    return pool_id2solvable(pkg->pool, pkg->id);
}

HyPackage
package_create(Pool *pool, Id id)
{
    HyPackage pkg;

    pkg = solv_calloc(1, sizeof(*pkg));
    pkg->pool = pool;
    pkg->id = id;
    return pkg;
}

HyPackage
package_from_solvable(Solvable *s)
{
    HyPackage pkg;

    if (!s)
	return NULL;
    pkg = solv_calloc(1, sizeof(*pkg));
    pkg->pool = s->repo->pool;
    pkg->id = s - s->repo->pool->solvables;
    return pkg;
}

void
hy_package_free(HyPackage pkg)
{
    solv_free(pkg);
}

int
hy_package_cmp(HyPackage pkg1, HyPackage pkg2)
{
    Pool *pool = pkg1->pool;
    Solvable *s1 = pool_id2solvable(pool, pkg1->id);
    Solvable *s2 = pool_id2solvable(pool, pkg2->id);
    const char *name1 = pool_id2str(pool, s1->name);
    const char *name2 = pool_id2str(pool, s2->name);
    int ret = strcmp(name1, name2);

   if (ret)
	return ret;
    return hy_package_evr_cmp(pkg1, pkg2);
}

int
hy_package_evr_cmp(HyPackage pkg1, HyPackage pkg2)
{
    Solvable *s1 = get_solvable(pkg1);
    Solvable *s2 = get_solvable(pkg2);

    return pool_evrcmp(pkg1->pool, s1->evr, s2->evr, EVRCMP_COMPARE);
}

char *
hy_package_get_location(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    repo_internalize_trigger(s->repo);
    return solv_strdup(solvable_get_location(s, NULL));
}

char *
hy_package_get_nvra(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    return solv_strdup(pool_solvable2str(pkg->pool, s));
}

const char*
hy_package_get_name(HyPackage pkg)
{
    Pool *pool = pkg->pool;
    return pool_id2str(pool, get_solvable(pkg)->name);
}

const char*
hy_package_get_arch(HyPackage pkg)
{
    Pool *pool = pkg->pool;
    return pool_id2str(pool, get_solvable(pkg)->arch);
}

const char*
hy_package_get_evr(HyPackage pkg)
{
    Pool *pool = pkg->pool;
    return pool_id2str(pool, get_solvable(pkg)->evr);
}

const char*
hy_package_get_reponame(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    return s->repo->name;
}

const char*
hy_package_get_summary(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    return solvable_lookup_str(s, SOLVABLE_SUMMARY);
}

int
hy_package_get_medianr(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    repo_internalize_trigger(s->repo);
    return solvable_lookup_num(s, SOLVABLE_MEDIANR, 0);
}

int
hy_package_get_rpmdbid(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    int idx = solvable_lookup_num(s, RPM_RPMDBID, 0);
    assert(idx > 0);
    return idx;
}

int
hy_package_get_size(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    repo_internalize_trigger(s->repo);
    return solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0) * 1024;
}<commit_msg>libsolv now gives us size in bytes.<commit_after>#include <assert.h>

//libsolv
#include "solv/evr.h"
#include "solv/pool.h"
#include "solv/repo.h"
#include "solv/util.h"

// hawkey
#include "iutil.h"
#include "package_internal.h"

static Solvable *
get_solvable(HyPackage pkg)
{
    return pool_id2solvable(pkg->pool, pkg->id);
}

HyPackage
package_create(Pool *pool, Id id)
{
    HyPackage pkg;

    pkg = solv_calloc(1, sizeof(*pkg));
    pkg->pool = pool;
    pkg->id = id;
    return pkg;
}

HyPackage
package_from_solvable(Solvable *s)
{
    HyPackage pkg;

    if (!s)
	return NULL;
    pkg = solv_calloc(1, sizeof(*pkg));
    pkg->pool = s->repo->pool;
    pkg->id = s - s->repo->pool->solvables;
    return pkg;
}

void
hy_package_free(HyPackage pkg)
{
    solv_free(pkg);
}

int
hy_package_cmp(HyPackage pkg1, HyPackage pkg2)
{
    Pool *pool = pkg1->pool;
    Solvable *s1 = pool_id2solvable(pool, pkg1->id);
    Solvable *s2 = pool_id2solvable(pool, pkg2->id);
    const char *name1 = pool_id2str(pool, s1->name);
    const char *name2 = pool_id2str(pool, s2->name);
    int ret = strcmp(name1, name2);

   if (ret)
	return ret;
    return hy_package_evr_cmp(pkg1, pkg2);
}

int
hy_package_evr_cmp(HyPackage pkg1, HyPackage pkg2)
{
    Solvable *s1 = get_solvable(pkg1);
    Solvable *s2 = get_solvable(pkg2);

    return pool_evrcmp(pkg1->pool, s1->evr, s2->evr, EVRCMP_COMPARE);
}

char *
hy_package_get_location(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    repo_internalize_trigger(s->repo);
    return solv_strdup(solvable_get_location(s, NULL));
}

char *
hy_package_get_nvra(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    return solv_strdup(pool_solvable2str(pkg->pool, s));
}

const char*
hy_package_get_name(HyPackage pkg)
{
    Pool *pool = pkg->pool;
    return pool_id2str(pool, get_solvable(pkg)->name);
}

const char*
hy_package_get_arch(HyPackage pkg)
{
    Pool *pool = pkg->pool;
    return pool_id2str(pool, get_solvable(pkg)->arch);
}

const char*
hy_package_get_evr(HyPackage pkg)
{
    Pool *pool = pkg->pool;
    return pool_id2str(pool, get_solvable(pkg)->evr);
}

const char*
hy_package_get_reponame(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    return s->repo->name;
}

const char*
hy_package_get_summary(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    return solvable_lookup_str(s, SOLVABLE_SUMMARY);
}

int
hy_package_get_medianr(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    repo_internalize_trigger(s->repo);
    return solvable_lookup_num(s, SOLVABLE_MEDIANR, 0);
}

int
hy_package_get_rpmdbid(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    int idx = solvable_lookup_num(s, RPM_RPMDBID, 0);
    assert(idx > 0);
    return idx;
}

int
hy_package_get_size(HyPackage pkg)
{
    Solvable *s = get_solvable(pkg);
    repo_internalize_trigger(s->repo);
    return solvable_lookup_num(s, SOLVABLE_DOWNLOADSIZE, 0);
}
{'fraction_non_alphanumeric': 0.13150214592274678, 'fraction_numerical': 0.01407725321888412, 'mean_word_length': 4.267631103074141, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5123571', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2332, 'n_words': 447}