本文整理汇总了C++中rotate_left函数的典型用法代码示例。如果您正苦于以下问题:C++ rotate_left函数的具体用法?C++ rotate_left怎么用?C++ rotate_left使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rotate_left函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: FI
/*
* KASUMI Encryption
*/
void KASUMI::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
u16bit B0 = load_be<u16bit>(in, 0);
u16bit B1 = load_be<u16bit>(in, 1);
u16bit B2 = load_be<u16bit>(in, 2);
u16bit B3 = load_be<u16bit>(in, 3);
for(size_t j = 0; j != 8; j += 2)
{
const u16bit* K = &m_EK[8*j];
u16bit R = B1 ^ (rotate_left(B0, 1) & K[0]);
u16bit L = B0 ^ (rotate_left(R, 1) | K[1]);
L = FI(L ^ K[ 2], K[ 3]) ^ R;
R = FI(R ^ K[ 4], K[ 5]) ^ L;
L = FI(L ^ K[ 6], K[ 7]) ^ R;
R = B2 ^= R;
L = B3 ^= L;
R = FI(R ^ K[10], K[11]) ^ L;
L = FI(L ^ K[12], K[13]) ^ R;
R = FI(R ^ K[14], K[15]) ^ L;
R ^= (rotate_left(L, 1) & K[8]);
L ^= (rotate_left(R, 1) | K[9]);
B0 ^= L;
B1 ^= R;
}
store_be(out, B0, B1, B2, B3);
in += BLOCK_SIZE;
out += BLOCK_SIZE;
}
}
开发者ID:Andrew-He,项目名称:botan,代码行数:43,代码来源:kasumi.cpp
示例2: right_balance
/*
* 右平衡旋转处理
* 新插入一个结点后,右子树高度大于左子树高度
*/
void
right_balance(struct avl **tree)
{
struct avl *right, *rl;
right = (*tree)->rchild;
switch (right->bf) {
case RH:
/* 右子树的BF为-1,与根结点的BF值-2符号相同,进行左旋操作 */
/* 即:平衡二叉树某一节点的右孩子的右子树上插入一个新的结点 */
(*tree)->bf = right->bf = EH; /* BF值设为0 */
rotate_left(tree);
break;
case LH:
/* 右子树的BF为1,与根结点的BF值-2符号相反,进行双旋转处理 */
rl = right->lchild; /* rl指向right的左子树 */
switch (rl->bf) { /* 修改tree和它的右孩子的BF */
case LH:
(*tree)->bf = EH;
right->bf = RH;
break;
case EH: /* 这个应该不会出现吧 */
(*tree)->bf = right->bf = EH;
break;
case RH:
(*tree)->bf = LH;
right->bf = EH;
break;
}
rl->bf = EH;
/* 先对tree的右子树进行右旋处理 */
rotate_right(&(*tree)->rchild);
/* 最后是对tree进行左旋处理 */
rotate_left(tree);
break;
}
}
开发者ID:weiqiangdragonite,项目名称:DataAndAlgo,代码行数:44,代码来源:avl_tree.c
示例3: equilibrate
static void equilibrate(SgBTreeNode *n, SgBTreeNode **root)
{
SgBTreeNode *p, *f;
SgSize lml, rml;
SgSize r;
for (;; n = p) {
p = n->parent;
f = NULL;
lml = n->left->mlevel;
rml = n->right->mlevel;
if (lml < rml) {
n->mlevel = rml + 1;
if ((r = rml - lml) == 1) {
if (rml > 1 && p->left == n)
f = rotate_left(n);
} else {
f = rotate_left(n);
if (r > 2)
equilibrate(n, &f);
}
} else if (lml > rml) {
n->mlevel = lml + 1;
if ((r = lml - rml) == 1) {
if (lml > 1 && p->right == n)
f = rotate_right(n);
} else {
f = rotate_right(n);
if (r > 2)
equilibrate(n, &f);
}
} else
n->mlevel = (lml > rml ? lml : rml) + 1;
if (n == *root) {
if (f)
*root = f;
break;
}
}
}
开发者ID:hasardel,项目名称:sigmae,代码行数:40,代码来源:dsaa3.c
示例4: balance_tree
/* balance tree after insertion of N */
static void balance_tree(ScmTreeCore *tc, Node *n)
{
Node *p = n->parent;
if (!p) { BALANCE_CASE("1"); n->color = BLACK; return; } /* root */
if (BLACKP(p)) { BALANCE_CASE("2"); return; } /* nothing to do */
/* Here we're sure we have grandparent. */
Node *g = p->parent;
SCM_ASSERT(g != NULL);
Node *u = (g->left == p)? g->right : g->left;
if (REDP(u)) {
p->color = u->color = BLACK;
g->color = RED;
BALANCE_CASE("3");
balance_tree(tc, g);
return;
}
if (n == p->right && p == g->left) {
rotate_left(tc, p);
n = n->left;
BALANCE_CASE("4a");
} else if (n == p->left && p == g->right) {
rotate_right(tc, p);
n = n->right;
BALANCE_CASE("4b");
}
p = n->parent;
g = p->parent;
p->color = BLACK;
g->color = RED;
if (n == p->left && p == g->left) {
rotate_right(tc, g);
BALANCE_CASE("5a");
} else {
rotate_left(tc, g);
BALANCE_CASE("5b");
}
}
开发者ID:abbrous,项目名称:Gauche,代码行数:41,代码来源:treemap.c
示例5: insert_case4
void insert_case4(rb_node* n, rb_tree* tree) {
rb_node* g = grandparent(n);
if ((n == n->parent->right) && (n->parent == g->left)) {
rotate_left(n->parent, tree);
n = n->left;
}
else if ((n == n->parent->left) && (n->parent == g->right)) {
rotate_right(n->parent, tree);
n = n->right;
}
insert_case5(n, tree);
}
开发者ID:hvidgaard,项目名称:AADS,代码行数:13,代码来源:rb_tree.c
示例6: theta
/*
* Noekeon Key Schedule
*/
void Noekeon::key_schedule(const byte key[], size_t)
{
u32bit A0 = load_be<u32bit>(key, 0);
u32bit A1 = load_be<u32bit>(key, 1);
u32bit A2 = load_be<u32bit>(key, 2);
u32bit A3 = load_be<u32bit>(key, 3);
for(size_t i = 0; i != 16; ++i)
{
A0 ^= RC[i];
theta(A0, A1, A2, A3);
A1 = rotate_left(A1, 1);
A2 = rotate_left(A2, 5);
A3 = rotate_left(A3, 2);
gamma(A0, A1, A2, A3);
A1 = rotate_right(A1, 1);
A2 = rotate_right(A2, 5);
A3 = rotate_right(A3, 2);
}
A0 ^= RC[16];
DK.resize(4);
DK[0] = A0;
DK[1] = A1;
DK[2] = A2;
DK[3] = A3;
theta(A0, A1, A2, A3);
EK.resize(4);
EK[0] = A0;
EK[1] = A1;
EK[2] = A2;
EK[3] = A3;
}
开发者ID:Kampbell,项目名称:botan,代码行数:42,代码来源:noekeon.cpp
示例7: delete_case2
void delete_case2(GtkWidget *darea, rbtree t, node n) {
if (node_color(sibling(n)) == RED) {
n->parent->color = RED;
sibling(n)->color = BLACK;
if (n == n->parent->left)
rotate_left(darea, t, n->parent);
else
rotate_right(darea, t, n->parent);
}
delete_case3(darea, t, n);
}
开发者ID:baalberith,项目名称:course-ansic,代码行数:13,代码来源:tree.c
示例8: encode
int encode( int enc_ch, int enc_shift ) {
int i;
if(enc_shift > 0 ) {
for(i=0;i<enc_shift;i++) {
enc_ch = rotate_right(enc_ch);
}
} else if (enc_shift < 0) {
for(i=0;i>enc_shift;i--) {
enc_ch = rotate_left(enc_ch);
}
}
return enc_ch;
}
开发者ID:Fuseken,项目名称:code,代码行数:13,代码来源:decaesar.c
示例9: rb_tree_insert_fixup
void rb_tree_insert_fixup (RBTREE *T , NODE *x) {
// this function is to fixup the rb-tree after calling rb_tree_insert
while (x->parent->color == RED) {
if (x->parent == x->parent->parent->left) {
NODE *y = x->parent->parent->right;
if (y->color == RED) {
y->color = BLACK;
x->parent->color = BLACK;
x->parent->parent->color = RED;
x = x->parent->parent;
}else if (y->color == BLACK) {
if (x == x->parent->right) {
x = x->parent;
rotate_left (T , x);
}
x->parent->color = BLACK;
x->parent->parent->color = RED;
rotate_right (T , x->parent->parent);
}
}else {
NODE *y = x->parent->parent->left;
if (y->color == RED) {
y->color = BLACK;
x->parent->color = BLACK;
x->parent->parent->color = RED;
x = x->parent->parent;
}else if (y->color == BLACK) {
if (x == x->parent->left) {
x = x->parent;
rotate_right (T , x);
}
x->parent->color = BLACK;
x->parent->parent->color = RED;
rotate_left (T , x->parent->parent);
}
}
}
T->root->color = BLACK;
}
开发者ID:buddyhelloXD,项目名称:mytinywebserver,代码行数:39,代码来源:rb_tree.c
示例10: RB_insert_fixup
void RB_insert_fixup(RB_tree *tree, RB_node *node){
node->color = RED;
RB_node *last;
while(node != tree->root && node->parent->color == RED){
if(is_left(node->parent)){
last = node->parent->parent->right;
if(last->color == RED){//1st CASE
node->parent->color = BLACK;
last->color = BLACK;
node->parent->parent->color = RED;
node = node->parent->parent;
}else{
if(node == node->parent->right){//2nd CASE --> 3rd
node = node->parent;
rotate_left(tree, node);
}
node->parent->color = BLACK;//3rd CASE
node->parent->parent->color = RED;
rotate_right(tree, node->parent->parent);
}
}else{
last = node->parent->parent->left;
if(last->color == RED){//1st CASE
node->parent->color = BLACK;
last->color = BLACK;
node->parent->parent->color = RED;
node = node->parent->parent;
}else{
if(node == node->parent->left){//2nd CASE --> 3rd
node = node->parent;
rotate_right(tree, node);
}
node->parent->color = BLACK;//3rd CASE
node->parent->parent->color = RED;
rotate_left(tree, node->parent->parent);
}
}
}
}
开发者ID:jedi1156,项目名称:PN-project,代码行数:39,代码来源:RBtree.c
示例11: permutate
void permutate(char *s, int start, int end) {
if (start < end) {
for (int i = start; i <= end; ++i) {
rotate_left(s, start, i);
permutate(s, start + 1, end);
rotate_right(s, start, i);
}
} else {
if (comma) printf(",");
printf("%s", s);
comma = 1;
}
}
开发者ID:chadheim,项目名称:code-eval,代码行数:13,代码来源:StringPermutations.c
示例12: fixup
/*
* 自底向上调整
*/
rbtree_node fixup(rbtree_node node){
/* 情况1:强制左倾 */
if( is_red(node->right) && !is_red(node->left) ){
node = rotate_left(node);
}
/* 情况2:调整平衡 */
if( is_red(node->left) && is_red(node->left->left))
node = rotate_right(node);
/* 情况3:分解4-node */
if( is_red(node->left) && is_red(node->right))
flip_colors(node);
return node;
}
开发者ID:CIPPUS-SSS,项目名称:assignment,代码行数:16,代码来源:rbtree.c
示例13: switch
// нажатие определенной клавиши
void Scene3D::keyPressEvent(QKeyEvent* pe)
{
switch (pe->key())
{
case Qt::Key_Plus:
scale_plus(); // приблизить сцену
break;
case Qt::Key_Equal:
scale_plus(); // приблизить сцену
break;
case Qt::Key_Minus:
scale_minus(); // удалиться от сцены
break;
case Qt::Key_Up:
rotate_up(); // повернуть сцену вверх
break;
case Qt::Key_Down:
rotate_down(); // повернуть сцену вниз
break;
case Qt::Key_Left:
rotate_left(); // повернуть сцену влево
break;
case Qt::Key_Right:
rotate_right(); // повернуть сцену вправо
break;
case Qt::Key_Z:
translate_down(); // транслировать сцену вниз
break;
case Qt::Key_X:
translate_up(); // транслировать сцену вверх
break;
case Qt::Key_Space: // клавиша пробела
defaultScene(); // возвращение значений по умолчанию
break;
case Qt::Key_Escape: // клавиша "эскейп"
this->close(); // завершает приложение
break;
}
updateGL(); // обновление изображения
}
开发者ID:Ztaz,项目名称:cpp,代码行数:52,代码来源:mouse_events.cpp
示例14: switch
void Scene3D::keyPressEvent(QKeyEvent* pe)
{
switch (pe->key())
{
case Qt::Key_Plus:
scale_plus();
break;
case Qt::Key_Equal:
scale_plus();
break;
case Qt::Key_Minus:
scale_minus();
break;
case Qt::Key_Up:
rotate_up();
break;
case Qt::Key_Down:
rotate_down();
break;
case Qt::Key_Left:
rotate_left();
break;
case Qt::Key_Right:
rotate_right();
break;
case Qt::Key_Z:
translate_down();
break;
case Qt::Key_X:
translate_up();
break;
case Qt::Key_Space:
defaultScene();
break;
case Qt::Key_Escape:
this->close();
break;
}
updateGL();
}
开发者ID:adrogolyub,项目名称:Spherical3d,代码行数:51,代码来源:scene3d.cpp
示例15: while
void balanced_pst::insert_fixup(node* z) {
while (z->p->color == RED) {
if (z->p == z->p->p->left) {
node* y = z->p->p->right;
if (y->color == RED) {
z->p->color = BLACK;
y->color = BLACK;
z->p->p->color = RED;
z = z->p->p;
} else {
if (z == z->p->right) {
z = z->p;
rotate_left(z);
}
z->p->color = BLACK;
z->p->p->color = RED;
rotate_right(z->p->p);
}
} else {
node* y = z->p->p->left;
if (y->color == RED) {
z->p->color = BLACK;
y->color = BLACK;
z->p->p->color = RED;
z = z->p->p;
} else {
if (z == z->p->left) {
z = z->p;
rotate_right(z);
}
z->p->color = BLACK;
z->p->p->color = RED;
rotate_left(z->p->p);
}
}
}
root->color = BLACK;
}
开发者ID:gabet1337,项目名称:speciale,代码行数:38,代码来源:balanced_pst.hpp
示例16: rotate_left
/*
* RC2 Encryption
*/
void RC2::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
for(size_t i = 0; i != blocks; ++i)
{
u16bit R0 = load_le<u16bit>(in, 0);
u16bit R1 = load_le<u16bit>(in, 1);
u16bit R2 = load_le<u16bit>(in, 2);
u16bit R3 = load_le<u16bit>(in, 3);
for(size_t j = 0; j != 16; ++j)
{
R0 += (R1 & ~R3) + (R2 & R3) + K[4*j];
R0 = rotate_left(R0, 1);
R1 += (R2 & ~R0) + (R3 & R0) + K[4*j + 1];
R1 = rotate_left(R1, 2);
R2 += (R3 & ~R1) + (R0 & R1) + K[4*j + 2];
R2 = rotate_left(R2, 3);
R3 += (R0 & ~R2) + (R1 & R2) + K[4*j + 3];
R3 = rotate_left(R3, 5);
if(j == 4 || j == 10)
{
R0 += K[R3 % 64];
R1 += K[R0 % 64];
R2 += K[R1 % 64];
R3 += K[R2 % 64];
}
}
store_le(out, R0, R1, R2, R3);
in += BLOCK_SIZE;
out += BLOCK_SIZE;
}
}
开发者ID:AlexNk,项目名称:botan,代码行数:41,代码来源:rc2.cpp
示例17: K
/*
* RC6 Key Schedule
*/
void RC6::key_schedule(const byte key[], size_t length)
{
const size_t WORD_KEYLENGTH = (((length - 1) / 4) + 1);
const size_t MIX_ROUNDS = 3 * std::max(WORD_KEYLENGTH, S.size());
S[0] = 0xB7E15163;
for(size_t i = 1; i != S.size(); ++i)
S[i] = S[i-1] + 0x9E3779B9;
SecureVector<u32bit> K(8);
for(s32bit i = length-1; i >= 0; --i)
K[i/4] = (K[i/4] << 8) + key[i];
u32bit A = 0, B = 0;
for(size_t i = 0; i != MIX_ROUNDS; ++i)
{
A = rotate_left(S[i % S.size()] + A + B, 3);
B = rotate_left(K[i % WORD_KEYLENGTH] + A + B, (A + B) % 32);
S[i % S.size()] = A;
K[i % WORD_KEYLENGTH] = B;
}
}
开发者ID:BenjaminSchiborr,项目名称:safe,代码行数:26,代码来源:rc6.cpp
示例18: tree_balance
/**
* Rebalance the dictionary tree.
* This recomputes the tree depth wayy too often, but so what.. this
* only wastes cpu time during the initial dictinary read.
*/
static Dict_node *rebalance(Dict_node *root)
{
int bal = tree_balance(root);
if (2 == bal)
{
bal = tree_balance(root->right);
if (-1 == bal)
{
root->right = rotate_right (root->right);
}
return rotate_left(root);
}
else if (-2 == bal)
{
bal = tree_balance(root->left);
if (1 == bal)
{
root->left = rotate_left (root->left);
}
return rotate_right(root);
}
return root;
}
开发者ID:dyne,项目名称:AutOrg,代码行数:28,代码来源:read-dict.c
示例19: insert_case4
void insert_case4(GtkWidget *darea, rbtree t, node n) {
if (n == n->parent->right && n->parent == grandparent(n)->left) {
rotate_left(darea, t, n->parent);
n = n->left;
}
else if (n == n->parent->left && n->parent == grandparent(n)->right) {
rotate_right(darea, t, n->parent);
n = n->right;
}
insert_case5(darea, t, n);
}
开发者ID:baalberith,项目名称:course-ansic,代码行数:14,代码来源:tree.c
示例20: delete_case6
void delete_case6(rb_node* n, rb_tree* tree) {
rb_node* s = sibling(n);
s->color = n->parent->color;
n->parent->color = BLACK;
if (n == n->parent->left) {
s->right->color = BLACK;
rotate_left(n->parent, tree);
} else {
s->left->color = BLACK;
rotate_right(n->parent, tree);
}
}
开发者ID:hvidgaard,项目名称:AADS,代码行数:14,代码来源:rb_tree.c
注:本文中的rotate_left函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论