eris: deterministic table length operator

This commit is contained in:
2021-07-05 12:12:32 -04:00
parent be529afc55
commit 596d829ea6

View File

@@ -558,21 +558,23 @@ static int unbound_search (Table *t, unsigned int j) {
** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
*/
int luaH_getn (Table *t) {
unsigned int j = t->sizearray;
if (j > 0 && ttisnil(&t->array[j - 1])) {
/* there is a boundary in the array part: (binary) search for it */
unsigned int i = 0;
while (j - i > 1) {
unsigned int m = (i+j)/2;
if (ttisnil(&t->array[m - 1])) j = m;
else i = m;
}
return i;
}
/* else must find a boundary in hash part */
else if (isdummy(t->node)) /* hash part is empty? */
return j; /* that is easy... */
else return unbound_search(t, j);
return unbound_search(t, 0);
// unsigned int j = t->sizearray;
// if (j > 0 && ttisnil(&t->array[j - 1])) {
// /* there is a boundary in the array part: (binary) search for it */
// unsigned int i = 0;
// while (j - i > 1) {
// unsigned int m = (i+j)/2;
// if (ttisnil(&t->array[m - 1])) j = m;
// else i = m;
// }
// return i;
// }
// /* else must find a boundary in hash part */
// else if (isdummy(t->node)) /* hash part is empty? */
// return j; /* that is easy... */
// else return unbound_search(t, j);
}