Browse Source

fixed 6 files out of 2928:

- removed 0 CR characters
 - removed 8 trailing whitespaces
 - replaced 400 tabs with spaces
 - fixed 6 svn:eol-style properties
undefined
Lolbot Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
56481be48e
2 changed files with 160 additions and 160 deletions
  1. +1
    -1
      demos/tutorial/13_shader_builder.cpp
  2. +159
    -159
      src/lol/base/avl_tree.h

+ 1
- 1
demos/tutorial/13_shader_builder.cpp View File

@@ -47,7 +47,7 @@ public:

String vertex_out = Shader::GetProgramOutVariableLocal(ShaderProgram::Vertex);
String pixel_out = Shader::GetProgramOutVariableLocal(ShaderProgram::Pixel);
String in_position = Shader::GetVariablePrefix(ShaderVariable::Attribute) + "position";
String in_color = Shader::GetVariablePrefix(ShaderVariable::Attribute) + "color";
String pass_color = Shader::GetVariablePrefix(ShaderVariable::Varying) + "color";


+ 159
- 159
src/lol/base/avl_tree.h View File

@@ -20,168 +20,168 @@ namespace lol
template<typename K, typename V>
class avl_tree
{
avl_tree() :
m_root(0)
{
}
bool insert(K const & key, V const & value)
{
if (!m_root)
this->m_root = new tree_node(key, value);
else
{
tree_node * created = this->m_root->insert(key, value);
if (created)
{
this->m_root->path_update_balance(created);
tree_node * new_root = this->m_root->path_rebalance(created);
if (new_root)
this->m_root = new_root;
}
else
return false;
}
return true;
}
avl_tree() :
m_root(0)
{
}
bool insert(K const & key, V const & value)
{
if (!m_root)
this->m_root = new tree_node(key, value);
else
{
tree_node * created = this->m_root->insert(key, value);
if (created)
{
this->m_root->path_update_balance(created);
tree_node * new_root = this->m_root->path_rebalance(created);
if (new_root)
this->m_root = new_root;
}
else
return false;
}
return true;
}

private:

class tree_node
{
tree_node(K key, V value) :
m_key(key),
m_value(value),
m_lo(0),
m_hi(0)
m_stairs_lo(0),
m_stairs_hi(0),
{
}
tree_node * insert(K const & key, V const & value)
{
tree_node * ret = 0;
if (key < this->m_key)
{
if (this->m_lo)
ret = this->m_lo->insert(key, value);
else
ret = this->m_lo = new tree_node(key, value);
}
else if (this->m_key < key)
{
if (this->m_hi)
ret = this->m_hi->insert(key, value);
else
ret = this->m_hi = new tree_node(key, value);
}
else
this->m_value = value;
return ret;
}
int path_update_balance(K const & key)
{
if (key < this->m_key)
this->m_stairs_lo = lol::max(this->m_lo->path_update_balance(node), this->m_stairs_lo);
else if (this->m_key < key)
this->m_stairs_hi = lol::max(this->m_hi->path_update_balance(node), this->m_stairs_hi);
return lol::max(this->m_stairs_lo, this->m_stairs_hi) + 1;
}
tree_node * path_rebalance(K const & key)
{
if (key < this->m_key)
{
tree_node * node = this->m_lo->path_rebalance();
if (node)
{
this->m_lo = node;
--this->m_lo;
}
}
else if (this->m_key < key)
{
tree_node * node = this->m_hi->path_rebalance();
if (node)
{
this->m_hi = node;
--this->m_hi;
}
}
if (this->m_stairs_lo - this->m_stairs_hi == 2)
{
return this->rotate();
}
else if (this->m_stairs_lo - this->m_stairs_hi == -2)
{
return this->rotate();
}
else
assert(lol::abs(this->m_stairs_lo - this->m_stairs_hi) < 3);
}
enum Rotation { CW = 0, CCW = 1 };
tree_node * rotate(Rotation rotation)
{
if (rotation == CW)
{
tree_node * lo = this->m_lo;
tree_node * lo_hi = this->m_lo->m_hi;
this->m_lo->m_hi = this;
this->m_lo = lo_hi;
this->compute_balance();
lo_hi->compute_balance();
return lo;
}
else // rotation == CCW
{
tree_node * hi = this->m_hi;
tree_node * hi_lo = this->m_hi->m_lo;
this->m_hi->m_lo = this;
this->m_hi = hi_lo;
this->compute_balance();
hi_lo->compute_balance();
return lo;
}
return 0;
}
void compute_balance()
{
this->m_stairs_lo = this->m_lo ? this->m_lo->m_stairs_lo + this->m_lo->m_stairs_hi : 0;
this->m_stairs_hi = this->m_hi ? this->m_hi->m_stairs_lo + this->m_lo->m_stairs_hi : 0;
}
private:
K m_key;
V m_value;
tree_node * m_lo;
tree_node * m_hi;
int m_stairs_lo;
int m_stairs_hi;
};
tree_node * m_root;
class tree_node
{
tree_node(K key, V value) :
m_key(key),
m_value(value),
m_lo(0),
m_hi(0)
m_stairs_lo(0),
m_stairs_hi(0),
{
}
tree_node * insert(K const & key, V const & value)
{
tree_node * ret = 0;
if (key < this->m_key)
{
if (this->m_lo)
ret = this->m_lo->insert(key, value);
else
ret = this->m_lo = new tree_node(key, value);
}
else if (this->m_key < key)
{
if (this->m_hi)
ret = this->m_hi->insert(key, value);
else
ret = this->m_hi = new tree_node(key, value);
}
else
this->m_value = value;
return ret;
}
int path_update_balance(K const & key)
{
if (key < this->m_key)
this->m_stairs_lo = lol::max(this->m_lo->path_update_balance(node), this->m_stairs_lo);
else if (this->m_key < key)
this->m_stairs_hi = lol::max(this->m_hi->path_update_balance(node), this->m_stairs_hi);
return lol::max(this->m_stairs_lo, this->m_stairs_hi) + 1;
}
tree_node * path_rebalance(K const & key)
{
if (key < this->m_key)
{
tree_node * node = this->m_lo->path_rebalance();
if (node)
{
this->m_lo = node;
--this->m_lo;
}
}
else if (this->m_key < key)
{
tree_node * node = this->m_hi->path_rebalance();
if (node)
{
this->m_hi = node;
--this->m_hi;
}
}
if (this->m_stairs_lo - this->m_stairs_hi == 2)
{
return this->rotate();
}
else if (this->m_stairs_lo - this->m_stairs_hi == -2)
{
return this->rotate();
}
else
assert(lol::abs(this->m_stairs_lo - this->m_stairs_hi) < 3);
}
enum Rotation { CW = 0, CCW = 1 };
tree_node * rotate(Rotation rotation)
{
if (rotation == CW)
{
tree_node * lo = this->m_lo;
tree_node * lo_hi = this->m_lo->m_hi;
this->m_lo->m_hi = this;
this->m_lo = lo_hi;
this->compute_balance();
lo_hi->compute_balance();
return lo;
}
else // rotation == CCW
{
tree_node * hi = this->m_hi;
tree_node * hi_lo = this->m_hi->m_lo;
this->m_hi->m_lo = this;
this->m_hi = hi_lo;
this->compute_balance();
hi_lo->compute_balance();
return lo;
}
return 0;
}
void compute_balance()
{
this->m_stairs_lo = this->m_lo ? this->m_lo->m_stairs_lo + this->m_lo->m_stairs_hi : 0;
this->m_stairs_hi = this->m_hi ? this->m_hi->m_stairs_lo + this->m_lo->m_stairs_hi : 0;
}
private:
K m_key;
V m_value;
tree_node * m_lo;
tree_node * m_hi;
int m_stairs_lo;
int m_stairs_hi;
};
tree_node * m_root;
};

}

Loading…
Cancel
Save