diff options
author | Nicolas Hillegeer <nicolas@hillegeer.com> | 2014-04-28 14:12:51 +0200 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-28 16:17:25 -0300 |
commit | d699ccfb0c3500becfec9b02c24dc858d54c5a6e (patch) | |
tree | 7178b1a7c0a1b90275f94a71851fbc106eae8d0a /test/unit/set.moon | |
parent | 349f9da850fe46853663bff4ca199045a4678837 (diff) | |
download | rneovim-d699ccfb0c3500becfec9b02c24dc858d54c5a6e.tar.gz rneovim-d699ccfb0c3500becfec9b02c24dc858d54c5a6e.tar.bz2 rneovim-d699ccfb0c3500becfec9b02c24dc858d54c5a6e.zip |
test: fix the cimport method
This commit will hopefully allow the cimport method to be used just as one
would use #inclue <header.h> in C. It follows the following method:
1. create a pseudoheader file that #include's all the requested header files
2. runs the pseudoheader through the C preprocessor (it will try various
compilers if available on the system).
3. runs the preprocessed file through a C formatter, which attempts to group
statements on one line. For example, a struct definition that was
formerly on several lines will take just one line after formatting. This
is done so that unique declarations can be detected. Duplicates are thus
easy to remove.
4. remove lines that are too complex for the LuaJIT C parser (such as:
Objective-C block syntax, crazy enums defined on linux, ...)
5. remove duplicate declarations
6. pass result to ffi.cdef
Diffstat (limited to 'test/unit/set.moon')
-rw-r--r-- | test/unit/set.moon | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/unit/set.moon b/test/unit/set.moon new file mode 100644 index 0000000000..daa312a2f4 --- /dev/null +++ b/test/unit/set.moon @@ -0,0 +1,72 @@ +-- a set class for fast union/diff, can always return a table with the lines +-- in the same relative order in which they were added by calling the +-- to_table method. It does this by keeping two lua tables that mirror each +-- other: +-- 1) index => item +-- 2) item => index +class Set + new: (items) => + if type(items) == 'table' + tempset = Set() + tempset\union_table(items) + @tbl = tempset\raw_tbl! + @items = tempset\raw_items! + @nelem = tempset\size! + else + @tbl = {} + @items = {} + @nelem = 0 + + -- adds the argument Set to this Set + union: (other) => + for e in other\iterator! + @add(e) + + -- adds the argument table to this Set + union_table: (t) => + for k,v in pairs(t) + @add(v) + + -- substracts the argument Set from this Set + diff: (other) => + if other\size! > @size! + -- this set is smaller than the other set + for e in @iterator! + if other\contains(e) + @remove(e) + else + -- this set is larger than the other set + for e in other\iterator! + if @items[e] + @remove(e) + + add: (it) => + if not @contains(it) + idx = #@tbl + 1 + @tbl[idx] = it + @items[it] = idx + @nelem += 1 + + remove: (it) => + if @contains(it) + idx = @items[it] + @tbl[idx] = nil + @items[it] = nil + @nelem -= 1 + + contains: (it) => + @items[it] or false + + size: => @nelem + raw_tbl: => @tbl + raw_items: => @items + iterator: => pairs(@items) + + to_table: => + -- there might be gaps in @tbl, so we have to be careful and sort first + keys = [idx for idx, _ in pairs(@tbl)] + table.sort(keys) + copy = [@tbl[idx] for idx in *keys] + copy + +return Set |