Skip to content

Commit 98a85d7

Browse files
authored
Update README.md
1 parent 63b9e94 commit 98a85d7

File tree

1 file changed

+77
-77
lines changed

1 file changed

+77
-77
lines changed

README.md

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -157,83 +157,6 @@ local rmean = require('algo.rmean')
157157
local my_collector = rmean.collector('my_collector')
158158
```
159159

160-
## Ordered Dictionary (algo.odict)
161-
162-
The collection tracks the order in which the items are added and provides
163-
`algo.odict.pairs()` function to get them in this order.
164-
165-
The ordered dictionary is a usual Lua table with a specific metatable. All the
166-
table operations are applicable.
167-
168-
It is similar to Python's [collections.OrderedDict][python-odict].
169-
170-
[python-odict]: https://docs.python.org/3/library/collections.html#collections.OrderedDict
171-
172-
Example:
173-
174-
```lua
175-
local od = odict.new()
176-
177-
od.a = 1
178-
od.b = 2
179-
od.c = 3
180-
181-
print('od.a', od.a) -- 1
182-
print('od.b', od.b) -- 2
183-
print('od.c', od.c) -- 3
184-
185-
for k, v in odict.pairs(od) do
186-
print(k, v)
187-
end
188-
-- print: a, 1
189-
-- print: b, 2
190-
-- print: c, 3
191-
```
192-
193-
If an element is changed (without prior deletion), it remains on the same
194-
position.
195-
196-
```lua
197-
local od = odict.new()
198-
199-
od.a = 1
200-
od.b = 2
201-
od.c = 3
202-
203-
od.b = 4
204-
205-
for k, v in odict.pairs(od) do
206-
print(k, v)
207-
end
208-
-- print: a, 1
209-
-- print: b, 4
210-
-- print: c, 3
211-
```
212-
213-
If an element is deleted and added again, it is added to the end.
214-
215-
```lua
216-
local od = odict.new()
217-
218-
od.a = 1
219-
od.b = 2
220-
od.c = 3
221-
222-
od.b = nil
223-
od.b = 4
224-
225-
for k, v in odict.pairs(od) do
226-
print(k, v)
227-
end
228-
-- print: a, 1
229-
-- print: c, 3
230-
-- print: b, 4
231-
```
232-
233-
Beware: Tarantool's REPL shows the fields as unordered. The same for the
234-
serialization into JSON/YAML/MessagePack formats. It should be solved after
235-
https://github.com/tarantool/tarantool/issues/9747.
236-
237160
#### Observing Values and Calculating Metrics
238161

239162
```lua
@@ -419,3 +342,80 @@ local my_rmean = rmean.new('my_rmean_instance', 1, 5)
419342

420343
- The system is automatically started when the rmean instance is created. Manual starting is only required if it was previously stopped.
421344
- The module efficiently handles moving average calculations even with a large number of parallel running collectors and provides high-performance metrics collection capabilities.
345+
346+
## Ordered Dictionary (algo.odict)
347+
348+
The collection tracks the order in which the items are added and provides
349+
`algo.odict.pairs()` function to get them in this order.
350+
351+
The ordered dictionary is a usual Lua table with a specific metatable. All the
352+
table operations are applicable.
353+
354+
It is similar to Python's [collections.OrderedDict][python-odict].
355+
356+
[python-odict]: https://docs.python.org/3/library/collections.html#collections.OrderedDict
357+
358+
Example:
359+
360+
```lua
361+
local od = odict.new()
362+
363+
od.a = 1
364+
od.b = 2
365+
od.c = 3
366+
367+
print('od.a', od.a) -- 1
368+
print('od.b', od.b) -- 2
369+
print('od.c', od.c) -- 3
370+
371+
for k, v in odict.pairs(od) do
372+
print(k, v)
373+
end
374+
-- print: a, 1
375+
-- print: b, 2
376+
-- print: c, 3
377+
```
378+
379+
If an element is changed (without prior deletion), it remains on the same
380+
position.
381+
382+
```lua
383+
local od = odict.new()
384+
385+
od.a = 1
386+
od.b = 2
387+
od.c = 3
388+
389+
od.b = 4
390+
391+
for k, v in odict.pairs(od) do
392+
print(k, v)
393+
end
394+
-- print: a, 1
395+
-- print: b, 4
396+
-- print: c, 3
397+
```
398+
399+
If an element is deleted and added again, it is added to the end.
400+
401+
```lua
402+
local od = odict.new()
403+
404+
od.a = 1
405+
od.b = 2
406+
od.c = 3
407+
408+
od.b = nil
409+
od.b = 4
410+
411+
for k, v in odict.pairs(od) do
412+
print(k, v)
413+
end
414+
-- print: a, 1
415+
-- print: c, 3
416+
-- print: b, 4
417+
```
418+
419+
Beware: Tarantool's REPL shows the fields as unordered. The same for the
420+
serialization into JSON/YAML/MessagePack formats. It should be solved after
421+
https://github.com/tarantool/tarantool/issues/9747.

0 commit comments

Comments
 (0)