Mercurial Hosting > luan
changeset 1100:ad6b3b9fef40
add Table.is_empty() and Table.size()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 21 May 2017 16:12:22 -0600 |
parents | a5406f076726 |
children | 14ffce5bb894 |
files | src/luan/LuanTable.java src/luan/modules/Table.luan src/luan/modules/TableLuan.java website/src/manual.html.luan |
diffstat | 4 files changed, 30 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/LuanTable.java Wed Apr 05 16:24:02 2017 -0600 +++ b/src/luan/LuanTable.java Sun May 21 16:12:22 2017 -0600 @@ -477,4 +477,17 @@ n ^= list.hashCode(); return n; } + + public boolean rawIsEmpty() { + return (map==null || map.isEmpty()) && (list==null || list.isEmpty()); + } + + public int rawSize() { + int n = 0; + if( map != null ) + n += map.size(); + if( list != null ) + n += list.size(); + return n; + } }
--- a/src/luan/modules/Table.luan Wed Apr 05 16:24:02 2017 -0600 +++ b/src/luan/modules/Table.luan Sun May 21 16:12:22 2017 -0600 @@ -8,17 +8,11 @@ Table.copy = TableLuan.copy Table.hash_value = TableLuan.hash_value Table.insert = TableLuan.insert +Table.is_empty = TableLuan.is_empty Table.pack = TableLuan.pack Table.remove = TableLuan.remove +Table.size = TableLuan.size Table.sort = TableLuan.sort Table.unpack = TableLuan.unpack - -local Luan = require "luan:Luan.luan" -local pairs = Luan.pairs - -function Table.is_empty(t) - return pairs(t)() == nil -end - return Table
--- a/src/luan/modules/TableLuan.java Wed Apr 05 16:24:02 2017 -0600 +++ b/src/luan/modules/TableLuan.java Sun May 21 16:12:22 2017 -0600 @@ -116,4 +116,12 @@ return tbl.hashValue(); } + public static boolean is_empty(LuanTable tbl) throws LuanException { + return tbl.rawIsEmpty(); + } + + public static int size(LuanTable tbl) throws LuanException { + return tbl.rawSize(); + } + }
--- a/website/src/manual.html.luan Wed Apr 05 16:24:02 2017 -0600 +++ b/website/src/manual.html.luan Sun May 21 16:12:22 2017 -0600 @@ -2736,6 +2736,10 @@ +<h4 heading><a name="Table.is_empty" href="#Table.is_empty"><code>Table.is_empty (tbl)</code></a></h4> + + + <h4 heading><a name="Table.pack" href="#Table.pack"><code>Table.pack (···)</code></a></h4> <p> @@ -2762,6 +2766,9 @@ +<h4 heading><a name="Table.size" href="#Table.size"><code>Table.size (tbl)</code></a></h4> + + <h4 heading><a name="Table.sort" href="#Table.sort"><code>Table.sort (list [, comp])</code></a></h4>