Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions doc/reference/reference_lua/table.rst
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
.. _table-module:
.. _table-module:

-------------------------------------------------------------------------------
Module table
-------------------------------------------------------------------------------

.. module:: table
.. module:: table

The :code:`table` module has everything in the
`standard Lua table library <https://www.lua.org/manual/5.1/manual.html#5.5>`_,
and some Tarantool extensions.

You can see this by saying "table": you will see this list of functions:
``clear`` (LuaJIT extension = erase all elements),
`concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (concatenate),
``copy`` (make a copy of an array),
``deepcopy`` (see description below),
``foreach``,
``foreachi``,
`getn <https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an array),
`insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (insert an element into an array),
`maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get largest index)
`move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (move elements between tables),
``new`` (LuaJIT extension = return a new table with pre-allocated elements),
`remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an element from an array),
`sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the elements of an array).
Write ``table`` to see the list of functions:

* ``clear`` (LuaJIT extension = erase all elements)
* `concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (concatenate)
* ``copy`` (make a copy of an array)
* ``deepcopy`` (see the :ref:`description <table-deepcopy>` below)
* ``foreach``
* ``foreachi``
* `getn <https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an array)
* `insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (insert an element into an array)
* `maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get the largest index)
* `move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (move elements between tables)
* ``new`` (LuaJIT extension = return a new table with pre-allocated elements)
* `remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an element from an array)
* `sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the elements of an array)

In this section we only discuss the additional function
that the Tarantool developers have added: ``deepcopy``.

.. _table-deepcopy:
.. _table-deepcopy:

.. function:: deepcopy(input-table)
.. function:: deepcopy(input-table)

Return a "deep" copy of the table -- a copy which follows
nested structures to any depth and does not depend on pointers,
Expand Down Expand Up @@ -60,29 +61,29 @@ that the Tarantool developers have added: ``deepcopy``.
- b
...

.. _table-sort:
.. _table-sort:

.. function:: sort(input-table [, comparison-function])
.. function:: sort(input-table [, comparison-function])

Put the input-table contents in sorted order.

The `basic Lua table.sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_
has a default comparison-function: :code:`function (a, b) return a < b end`.
has a default comparison function: :code:`function (a, b) return a < b end`.

That is efficient and standard. However, sometimes Tarantool users
will want an equivalent to ``table.sort`` which has any of these features:

(1) If the table contains nils, except nils at the end, the results must still be correct.
That is not the case with the default tarantool_sort, and it cannot
be fixed by making a comparison that checks whether a and b are nil.
(Before trying certain Internet suggestions, test with
{1, nil, 2, -1, 44, 1e308, nil, 2, nil, nil, 0}.
#. If the table contains nils, except nils at the end, the results must still be correct.
That is not the case with the default ``tarantool_sort``, and it cannot
be fixed by making a comparison that checks whether ``a`` and ``b`` are ``nil``.
(Before trying certain Internet suggestions, test with
:code:`{1, nil, 2, -1, 44, 1e308, nil, 2, nil, nil, 0}`.

(2) If strings are to be sorted in a language-aware way, there must be a
parameter for collation.
#. If strings are to be sorted in a language-aware way, there must be a
parameter for collation.

(3) If the table has a mix of types, then they must be sorted as
booleans, then numbers, then strings, then byte arrays.
#. If the table has a mix of types, then they must be sorted as
booleans, then numbers, then strings, then byte arrays.

Since all those features are available in Tarantool spaces,
the solution for Tarantool is simple: make a temporary Tarantool
Expand All @@ -94,7 +95,9 @@ that the Tarantool developers have added: ``deepcopy``.
it requires a database privilege, so it should only be used if the
extra features are necessary.

.. code-block:: none
**Example:**

.. code-block:: lua

function tarantool_sort(input_table, collation)
local c = collation or 'binary'
Expand All @@ -118,5 +121,7 @@ that the Tarantool developers have added: ``deepcopy``.
box.space[tmp_name]:drop()
end

For example, suppose table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.
After tarantool_sort(t, 'unicode_ci') t contains {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}.

For example, suppose :code:`table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}`.

After ``tarantool_sort(t, 'unicode_ci')`` ``t`` contains :code:`{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}`.
98 changes: 47 additions & 51 deletions locale/ru/LC_MESSAGES/reference/reference_lua/table.po
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,35 @@ msgstr ""
"некоторые расширения специально для Tarantool."

msgid ""
"You can see this by saying \"table\": you will see this list of functions: "
"``clear`` (LuaJIT extension = erase all elements), `concat "
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ "
"(concatenate), ``copy`` (make a copy of an array), ``deepcopy`` (see "
"description below), ``foreach``, ``foreachi``, `getn "
"<https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an "
"array), `insert <https://www.lua.org/manual/5.1/manual.html#pdf-"
"table.insert>`_ (insert an element into an array), `maxn "
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get largest "
"index) `move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ "
"(move elements between tables), ``new`` (LuaJIT extension = return a new "
"table with pre-allocated elements), `remove "
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an "
"element from an array), `sort "
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the "
"elements of an array)."
"Write ``table`` to see the list of functions: "
"``clear`` (LuaJIT extension = erase all elements)"
"`concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (concatenate)"
"``copy`` (make a copy of an array)"
"``deepcopy`` (see the :ref:`description <table-deepcopy>` below)"
"``foreach``"
"``foreachi``"
"`getn <https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an array)"
"`insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (insert an element into an array)"
"`maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get еру largest index)"
"`move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (move elements between tables)"
"``new`` (LuaJIT extension = return a new table with pre-allocated elements)"
"`remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an element from an array)
"`sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the elements of an array)"
msgstr ""
"Чтобы убедиться в этом, выполните команду \"table\": вы увидите список "
"функций: ``clear`` (расширение LuaJIT = удаление всех элементов), `concat "
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ "
"(конкатенация), ``copy`` (создание копии массива), ``deepcopy`` (см. "
"описание ниже), ``foreach``, ``foreachi``, `getn "
"<https://www.lua.org/pil/19.1.html>`_ (получение количества элементов в "
"массиве), `insert <https://www.lua.org/manual/5.1/manual.html#pdf-"
"table.insert>`_ (вставка элемента в массив), `maxn "
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (получение "
"самого большого индекса) `move "
"<https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (перемещение "
"элементов между таблицами), ``new`` (расширение LuaJIT = возврат новой "
"таблицы с предварительно выделенными элементами), `remove "
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (удаление "
"элемента из массива), `sort <https://www.lua.org/manual/5.1/manual.html#pdf-"
"table.sort>`_ (сортировка элементов массива)."
"Чтобы убедиться в этом, выполните команду \"table\": вы увидите список функций: "
"``clear`` (расширение LuaJIT = удаление всех элементов),"
"`concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (конкатенация),"
"``copy`` (создание копии массива),"
"``deepcopy`` (см. :ref:`описание <table-deepcopy>` ниже),"
"``foreach``,"
"``foreachi``,"
"`getn <https://www.lua.org/pil/19.1.html>`_ (получение количества элементов в массиве),"
"`insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (вставка элемента в массив),"
"`maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (получение самого большого индекса),"
"`move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (перемещение элементов между таблицами),"
"``new`` (расширение LuaJIT = возврат новой таблицы с предварительно выделенными элементами),"
"`remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (удаление элемента из массива),"
"`sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (сортировка элементов массива)."

msgid ""
"In this section we only discuss the additional function that the Tarantool "
Expand Down Expand Up @@ -117,7 +113,7 @@ msgstr "Размещение содержимого введенной табл

msgid ""
"The `basic Lua table.sort <https://www.lua.org/manual/5.1/manual.html#pdf-"
"table.sort>`_ has a default comparison-function: :code:`function (a, b) "
"table.sort>`_ has a default comparison function: :code:`function (a, b) "
"return a < b end`."
msgstr ""
"В базовой сортировке в Lua, `table.sort "
Expand All @@ -133,31 +129,31 @@ msgstr ""
"может понадобиться эквивалент ``table.sort`` со следующими функциями:"

msgid ""
"(1) If the table contains nils, except nils at the end, the results must "
"still be correct. That is not the case with the default tarantool_sort, and "
"it cannot be fixed by making a comparison that checks whether a and b are "
"nil. (Before trying certain Internet suggestions, test with {1, nil, 2, -1, "
"44, 1e308, nil, 2, nil, nil, 0}."
"#. If the table contains nils, except nils at the end, the results must "
"still be correct. That is not the case with the default ``tarantool_sort``, and "
"it cannot be fixed by making a comparison that checks whether ``a`` and ``b`` are "
"``nil``. (Before trying certain Internet suggestions, test with :code:`{1, nil, 2, -1, "
"44, 1e308, nil, 2, nil, nil, 0}`."
msgstr ""
"(1) Если таблица содержит нулевые значения, за исключением нулей в конце, "
"#. Если таблица содержит нулевые значения, за исключением нулей в конце, "
"результаты все равно должны быть правильными. Это не работает при "
"использовании стандартного tarantool_sort, и это нельзя исправить, выполнив "
"сравнение, которое проверяет, равны ли значения a и b нулю. (Прежде чем "
"пробовать определенные предложения в Интернете, проверьте {1, nil, 2, -1, "
"44, 1e308, nil, 2, nil, nil, 0}."
"использовании стандартного ``tarantool_sort``, и это нельзя исправить, выполнив "
"сравнение, которое проверяет, равны ли значения ``a`` и ``b`` нулю. (Прежде чем "
"пробовать определенные предложения в Интернете, проверьте ``{1, nil, 2, -1, "
"44, 1e308, nil, 2, nil, nil, 0}``."

msgid ""
"(2) If strings are to be sorted in a language-aware way, there must be a "
"#. If strings are to be sorted in a language-aware way, there must be a "
"parameter for collation."
msgstr ""
"(2) Если строки должны быть отсортированы с учетом языка, должен быть "
"#. Если строки должны быть отсортированы с учетом языка, должен быть "
"параметр для сравнения символов."

msgid ""
"(3) If the table has a mix of types, then they must be sorted as booleans, "
"#. If the table has a mix of types, then they must be sorted as booleans, "
"then numbers, then strings, then byte arrays."
msgstr ""
"(3) Если в таблица есть разные типы, то они должны быть отсортированы так: "
"#. Если в таблица есть разные типы, то они должны быть отсортированы так: "
"логические, затем числа, затем строки, а затем байтовые массивы."

msgid ""
Expand Down Expand Up @@ -204,8 +200,8 @@ msgid ""
" box.space[tmp_name]:drop()\n"
" end\n"
"\n"
"For example, suppose table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.\n"
"After tarantool_sort(t, 'unicode_ci') t contains {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}."
"For example, suppose :code:`table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}`.\n"
"After ``tarantool_sort(t, 'unicode_ci')`` ``t`` contains :code:`{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}`."
msgstr ""
"function tarantool_sort(input_table, collation)\n"
" local c = collation or 'binary'\n"
Expand All @@ -229,5 +225,5 @@ msgstr ""
" box.space[tmp_name]:drop()\n"
" end\n"
"\n"
"Например, предположим, что таблица t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.\n"
"После tarantool_sort(t, 'unicode_ci') t содержит {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}."
"Например, предположим, что таблица ``t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}``.\n"
"После ``tarantool_sort(t, 'unicode_ci')`` ``t`` содержит ``{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}``."