-
Notifications
You must be signed in to change notification settings - Fork 5
/
NODE.m
46 lines (45 loc) · 1.33 KB
/
NODE.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
classdef NODE < handle
% A node in the tree
properties
value;
left = [];
right = [];
end
methods
function obj = NODE(varargin)
obj.value = varargin{1};
if nargin > 1
obj.left = varargin{2};
if nargin > 2
obj.right = varargin{3};
end
end
end
function out = type(obj)
% Type of node: 0. operand 1. unary operator 2. binary operator
if isempty(obj.left)
out = 0;
elseif isempty(obj.right)
out = 1;
else
out = 2;
end
end
function out = iscons(obj)
% Whether the node is a constant
out = obj.value <= 1;
end
function out = isscalar(obj)
% Whether the node is a scalar
out = ismember(obj.value,[1,3,7]) || obj.value <= 1;
end
function out = isbinary(obj)
% Whether the node is a binary operator
out = ismember(obj.value,[11,12,13,14]);
end
function out = isvector(obj)
% Whether the node is a vector-oriented operator
out = ismember(obj.value,[32,33,34,35,36]);
end
end
end