[Vala] [vala] problem with sorting an array
- From: raum no-log org
- To: vala-list gnome org
- Subject: [Vala] [vala] problem with sorting an array
- Date: Wed, 29 Aug 2018 12:39:43 +0200
Hi all,
I don't understand why I can't sotr my array... :-/ (glib.array)
Could you give me an advice ?
My code below..
Thanks
Raum
-----------------------------------------------------
public class FileAndChunks {
public string filename;
public int64 size;
}
int sort_by_size(FileAndChunks o1, FileAndChunks o2)
{
return (int) (o1.size > o2.size) - (int) (o1.size < o2.size);
}
public static void main (string[] args) {
Array<FileAndChunks> list = new Array<FileAndChunks>();
FileAndChunks f;
f = new FileAndChunks();
f.size = 8620258;
f.filename = "Sd9YYxjP";
list.append_val(f);
f = new FileAndChunks();
f.size = 6839026;
f.filename = "ybJI6spa";
list.append_val(f);
f = new FileAndChunks();
f.size = 778;
f.filename = "ilWcr20t";
list.append_val(f);
f = new FileAndChunks();
f.size = 0;
f.filename = "ad46NgIK";
list.append_val(f);
f = new FileAndChunks();
f.size = 3513;
f.filename = "dHqrduFS";
list.append_val(f);
f = new FileAndChunks();
f.size = 57109;
f.filename = "Qe0RN69c";
list.append_val(f);
f = new FileAndChunks();
f.size = 4297;
f.filename = "l7CqBp4k";
list.append_val(f);
f = new FileAndChunks();
f.size = 1478;
f.filename = "Mlm3qjai";
list.append_val(f);
f = new FileAndChunks();
f.size = 522;
f.filename = "XiwKxxgX";
list.append_val(f);
print ("BEFORE\n");
for (int i = 0; i < list.length; i++) {
f = list.index(i);
print ("%s => %d\n", f.filename, (int) f.size);
}
list.sort_with_data(sort_by_size);
print ("\n\nAFTER\n");
for (int i = 0; i < list.length; i++) {
f = list.index(i);
print ("%s => %d\n", f.filename, (int) f.size);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]