What's the word for "left or right" ?

I can't seem to google the answer. For example, parity is the word for odd or even. Because of the repeated patterns for all the left and right actions in binary trees, I want to use a template argument to generalize all the left and right actions and essentially cut the code into half. I'm using enum LR {Left, Right}; for now, but what is the proper word?

And while we are here, the following is the only way I can think of to get started. Is there a better/cleaner way than this, keeping in mind that Node is an inner class of the template class BinaryTree<T, Comparator>?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
template <typename T, typename Comparator>
class BinaryTree {
	class Node : public std::enable_shared_from_this<Node> {
		T value;
		std::shared_ptr<Node> left = nullptr, right = nullptr, parent = nullptr;
		// ...
		template <LR, typename P = void> struct Child;
		template <typename P> struct Child<Left, P> { static std::shared_ptr<Node>& get(Node* node) {return node->left;} };
		template <typename P> struct Child<Right, P> { static std::shared_ptr<Node>& get(Node* node) {return node->right;} };
		template <LR Z> std::shared_ptr<Node>& child() {return Child<Z>::get(this);}
                template <LR Z> std::shared_ptr<Node>& otherChild() {return Child<OtherLR<Z>::value>::get(this);}
	};
        // ...
};


So now node->child<Left>() is node->left and node->child<Right>() is node->right,
and
node->otherChild<Left>() is node->right and node->otherChild<Right>() is node->left, where

1
2
3
4
5
enum LR {Left, Right};

template <LR> struct OtherLR;
template <> struct OtherLR<Left> : std::integral_constant<LR, Right> {};
template <> struct OtherLR<Right> : std::integral_constant<LR, Left> {};

Last edited on
In the context of binary trees left and right refers to subtrees, right? So could you not use the word subtree?
Last edited on
No. See the above example? It could refer to left and right child. I will also want to make rotateLeft and rotateRight generic too.
Last edited on
I think 'Side' is good enough. Or you could just use a bool named 'rightness' and then define const bool right_side = true and const bool left_side = false.
AFAIK there is no one word in English to succinctly express "left or right".

Things that are close include "side", "handedness", and "direction".
->AFAIK there is no one word in English to succinctly express "left or right".

Hmmm.... Then there ought to be.

I'll go with 'Side' then, because it is short.
Yaw? (as in pitch roll yaw)
"Sidedness" and "laterality" could conceivably be used also, but they refer to a general preference for one side over the other, rather than to a definite choice.
Regarding my second question, I've thought of a slightly cleaner implementation (and using the name 'Side' now), using overload instead of a meta-function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
enum Side {Left, Right};

template <Side> struct OtherSide;
template <> struct OtherSide<Left> : std::integral_constant<Side, Right> {};
template <> struct OtherSide<Right> : std::integral_constant<Side, Left> {};

template <typename T, typename Comparator>
class BinaryTree {
	class Node : public std::enable_shared_from_this<Node> {
		T value;
		std::shared_ptr<Node> left = nullptr, right = nullptr, parent = nullptr;
		std::size_t subtreeSize, subtreeHeight, depthFromRoot;
		template <Side> struct Child {};
                // ...
		std::shared_ptr<Node>& getChild (const Child<Left>&) {return left;}
		std::shared_ptr<Node>& getChild (const Child<Right>&) {return right;}
		template <Side LR> std::shared_ptr<Node>& child() {return getChild(Child<LR>{});}
		template <Side LR> std::shared_ptr<Node>& otherChild() {return getChild(Child<OtherSide<LR>::value>{});}
	};
        // ...
};


Other ways of implementing this are welcomed.
Last edited on
closed account (48T7M4Gy)
What's the word for "left or right" ?

'child' is the correct term for binary trees as in left-child and right-child (as mentioned above by presto)

Refer "Data Structures with C++ Using STL" 2nd edition W Ford & W Topp p 506, 507
Last edited on
child left and right , you can also add a state writher it is a leaf
closed account (48T7M4Gy)
State writher/writhe technology would indeed be an interesting way of looking at binary trees. It could simplify things dramatically.
Topic archived. No new replies allowed.