Must admit that i love these parts of Computer Sciences that have elegant, scientific notation.
Tuples / pl: 'Krotki' / are nice that way, as well.
For example:
(char, int8, int8, string) t1 := ('a', 1, 3, "sample string");
(int8, int8) t2 := (2,3);
Uses.
Was thinking about how to implement Tuple Data Type in 'Ola' Programming Language.
Preconditions.
i think that every object used with 'Ola' Programming Language ... should have a 'name' string as a part of its runtime state, randomly generated at first, with Random Number Generator initialized with a Time Stamp.
i think it should be possible to rename any/every of object(s).
Succesful working of the Tuple Data Type depends on above preconditions. Without these preconditions, this article should be either edited or removed.
Implementation Considerations.
Was thinking about how to implement Tuple Data Type in 'Ola' Programming Language - and came with that a tuple - internally - should consist of:
- String Array with runtime object names,
- Map where object name string is key and TupleValue is value.
Invariant: During Map's observable moments, name strings in Map are sorted alphabetically.
TupleValue has:
- object's type / not sure yet how to encode it /,
- object's value / according with it's type /.
Benefits.
1. Using String Array and Map, we provide support for objects graph that can contain cycles.
Names in objects' runtime state are also important tool for avoiding 'infinite recursion' loops in graphs with cycles.
2. Thanks to String Array and Map data types used, it's cheap and easy to find n-th value in a tuple ... both n-th key, as well as n-th TupleValue.
For example:
(int8, int8, int8) t := (1,5,3);
String tk := t.getKey(2);
TupleValue tv := t.getValue(2);
3. We can also quickly get String Array part of a Tuple ... in which an unsorted copy of keyset is kept.
For example:
(int32, int8, int8, int8) t := (15,6,5,3);
String[] keys := t.getKeys();
4. Giving a name to a tuple value is also cheap and easy,
(int8, int8, int8) t := (2,4,3);
t.setName(2, "name for 3");
// both String Array, as well as Map's key are updated ... both need to be a part of a single atomic operation.
5. Searching for a tuple value by its name is also easy and cheap.
(char, int8, string, int8) t := ('2',4,"one",0);
t.setName(2, "name for one");
TupleValue tv := t.getTupleValueByName("name for one");
Links.
- Linda & Tuple Space,
- Algorithms' Time-Performance Metrics.
No comments:
Post a Comment