示例#1
0
static int
compare_by_activity (GtkTreeModel * m,
                     GtkTreeIter  * a,
                     GtkTreeIter  * b,
                     gpointer       user_data)
{
  int ret = 0;
  tr_torrent *ta, *tb;
  const tr_stat *sa, *sb;
  double aUp, aDown, bUp, bDown;

  gtk_tree_model_get (m, a, MC_SPEED_UP, &aUp,
                            MC_SPEED_DOWN, &aDown,
                            MC_TORRENT, &ta,
                            -1);
  gtk_tree_model_get (m, b, MC_SPEED_UP, &bUp,
                            MC_SPEED_DOWN, &bDown,
                            MC_TORRENT, &tb,
                            -1);
  sa = tr_torrentStatCached (ta);
  sb = tr_torrentStatCached (tb);

  if (!ret)
    ret = compare_double (aUp+aDown, bUp+bDown);
  if (!ret)
    ret = compare_uint64 (sa->uploadedEver, sb->uploadedEver);
  if (!ret)
    ret = compare_by_queue (m, a, b, user_data);

  return ret;
}
示例#2
0
static int
compare_path_t(DB *dbp, const DBT *in_a, const DBT *in_b)
{
	DBT		a;
	DBT		b;
	uint64_t	ai;
	uint64_t	bi;
	int		st;

	memcpy(&ai, in_a->data, 8);
	memcpy(&bi, in_b->data, 8);

	st = compare_uint64(ai, bi);

	if (st == 0) {
		a.data = ((path_t *)(in_a->data))->pathname;
		a.size = in_a->size - 8;

		b.data = ((path_t *)(in_b->data))->pathname;
		b.size = in_b->size - 8;

		st = compare_pathname(dbp, &a, &b);
	}
	return (st);
}
示例#3
0
static int
bt_compare_sfid(DB *dbp, const DBT *in_a, const DBT *in_b) /* ARGSUSED */
{
	uint64_t 	a = 0;
	uint64_t	b = 0;
	uint32_t	c = 0;
	uint32_t	d = 0;
	sfid_t		*af;
	sfid_t		*bf;
	int		st;

	if (in_a->size) {
		af = (sfid_t *)(in_a->data);

		memcpy(&a, &(af->fid), 8);
		memcpy(&c, &(af->snapid), 4);
	}

	if (in_b->size) {
		bf = (sfid_t *)(in_b->data);

		memcpy(&b, &(bf->fid), 8);
		memcpy(&d, &(bf->snapid), 4);
	}

	/* compare the snapshot id, oldest first */
	st = compare_uint32(c, d);

	/* if they're equal, secondary sort on file id */
	if (st == 0) {
		st = compare_uint64(a, b);
	}

	return (st);
}
示例#4
0
/*
 * function used to facilitate insert sorts for BTREE databases with
 * fuid_t and sfid_t keys.  As both of these are comprised of 1 uint64_t
 * value and 1 uint32_t value, we can use the same compare function.
 */
static int
bt_compare_fuid(DB *dbp, const DBT *in_a, const DBT *in_b) /* ARGSUSED */
{
	uint64_t 	a = 0;
	uint64_t	b = 0;
	uint32_t	c = 0;
	uint32_t	d = 0;
	fuid_t		*af;
	fuid_t		*bf;
	int		st;

	/* compare the first uint64_t */
	if (in_a->size) {
		af = (fuid_t *)(in_a->data);
		memcpy(&a, &(af->fid), 8);
		memcpy(&c, &(af->mtime), 4);
	}

	if (in_b->size) {
		bf = (fuid_t *)(in_b->data);
		memcpy(&b, &(bf->fid), 8);
		memcpy(&d, &(bf->mtime), 4);
	}

	st = compare_uint64(a, b);

	/* if they're equal, subsort on second value */
	if (st == 0) {
		/* reverse sort - newer first */
		st = compare_uint32(d, c);
	}

	return (st);
}
示例#5
0
/*
 * function used to facilitate insert sorts for BTREE databases with
 * uint64_t keys.  The default insert sort algorithm is VERY inefficient
 * on little endian systems (x64) as it tries to sort lexically.
 */
int
bt_compare_uint64(DB *dbp, const DBT *in_a, const DBT *in_b) /* ARGSUSED */
{
	uint64_t	a = 0;
	uint64_t	b = 0;

	if (in_a->size) {
		memcpy(&a, in_a->data, 8);
	}

	if (in_b->size) {
		memcpy(&b, in_b->data, 8);
	}

	return (compare_uint64(a, b));
}
示例#6
0
static int
compare_by_size (GtkTreeModel * m,
                 GtkTreeIter  * a,
                 GtkTreeIter  * b,
                 gpointer       u)
{
  int ret = 0;
  tr_torrent *t;
  const tr_info *ia, *ib;

  gtk_tree_model_get (m, a, MC_TORRENT, &t, -1);
  ia = tr_torrentInfo (t);
  gtk_tree_model_get (m, b, MC_TORRENT, &t, -1);
  ib = tr_torrentInfo (t);

  if (!ret)
    ret = compare_uint64 (ia->totalSize, ib->totalSize);
  if (!ret)
    ret = compare_by_name (m, a, b, u);

  return ret;
}