Example #1
0
HRESULT ComRegistration::unregisterCoClass( CLSID clsid,  WCHAR* ProgID )
{
	HRESULT hr;

	WCHAR * lpwCLSID;
	hr = StringFromCLSID( clsid, &lpwCLSID );
	if ( hr != S_OK ) return hr;

	std::wstring wCLSID = L"CLSID\\" + std::wstring(lpwCLSID);

	//[ HKCR\CLSID\{CLSID_X}\InProcServer32 ]
	hr = deleteKey( HKEY_CLASSES_ROOT, wCLSID.c_str(), L"InProcServer32" );
	if( !SUCCEEDED(hr) ) { return hr; }

	//[ HKCR\CLSID\{CLSID_X}\ProgID ]
	hr = deleteKey( HKEY_CLASSES_ROOT, wCLSID.c_str(), L"ProgID" );
	if( !SUCCEEDED(hr) ) { return hr; }

	//[ HKCR\CLSID\{CLSID_X} ]
	hr = deleteKey( HKEY_CLASSES_ROOT, L"CLSID", lpwCLSID );
	if( !SUCCEEDED(hr) ) { return hr; }

	//[ HKCR\CLSID\<ProgID>\CLSID ]
	hr = deleteKey( HKEY_CLASSES_ROOT, ProgID, L"CLSID" );
	if( !SUCCEEDED(hr) ) { return hr; }

	//[ HKCR\CLSID\<ProgID> ]
	hr = deleteKey( HKEY_CLASSES_ROOT, NULL, ProgID );
	
	return hr;

}
Example #2
0
  ITNode<Key>* deleteKey(ITNode<Key>* arg, Key *k)
{
#ifdef debugid
  std::cout << "Deleting.. " << *k << " from " << *arg << "\n";
#endif
  assert(arg->contains(k));
  if(arg->key == k) {
    if(arg->lesser->key == NULL || arg->greater->key == NULL) {
      ITNode<Key>* ret;
      if(arg->lesser->key == NULL) {
        ret = arg->greater;
        arg->greater = NULL;
        delete(arg);
      }
      else {
      ret = arg->lesser;
      arg->lesser = NULL;
      delete(arg);
      }
      return ret;
    }
    ITNode<Key>* min = arg->greater->findMin();
    Key* minkey = min->key;
    arg->greater = deleteKey(arg->greater, minkey);
    arg->accum += minkey->val - arg->key->val;
    arg->key = minkey;
  } else {
    if(arg->compareNode(k)) {
      arg->lesser = deleteKey(arg->lesser, k);
      arg->accum -= k->val;
    } else {
      arg->greater = deleteKey(arg->greater, k);
    }
  }
  arg->updateHeight();
  arg->updateTreeMax();
  //std::cout << " = " << *arg << " => " << arg->getBalance() << "\n";
  if(arg->getBalance() == 2) {
    if( arg->lesser->getBalance() >= 0) {
      return arg->rotateRight();
    } else {
      arg->lesser = arg->lesser->rotateLeft();
      return arg->rotateRight();
    }
  }
  if(arg->getBalance() == -2) {
    if(arg->greater->getBalance() <= 0) {
      return arg->rotateLeft();
    } else {
      arg->greater = arg->greater->rotateRight();
      return arg->rotateLeft();
    }
  }
  return arg;
}
Example #3
0
  ITNode<Key>* deleteKey(ITNode<Key>* arg, Key *k)
{
  //std::cout << "Deleting.. " << *k << " from " << *arg << "\n";
  if(arg->key == NULL)
    return arg;
  if(arg->key == k) {
    if(arg->lesser->key == NULL || arg->greater->key == NULL) {
      ITNode<Key>* ret;
      if(arg->lesser->key == NULL) {
        ret = arg->greater;
        arg->greater=NULL;
        delete(arg);
        return ret;
      }
      ret = arg->lesser;
      arg->lesser = NULL;
      delete(arg);
      return ret;
    }
    ITNode<Key>* min = arg->greater->findMin();
    Key* minkey = min->key;
    arg->greater = deleteKey(arg->greater, minkey);
    arg->key = minkey;
  }
  if(*k < *arg->key) {
    arg->lesser = deleteKey(arg->lesser, k);
  } else {
    arg->greater = deleteKey(arg->greater, k);
  }
  arg->updateHeight();
  //std::cout << " = " << *arg << " => " << arg->getBalance() << "\n";
  if(arg->getBalance() == 2) {
    if( arg->lesser->getBalance() >= 0) {
      return arg->rotateRight();
    } else {
      arg->lesser = arg->lesser->rotateLeft();
      return arg->rotateRight();
    }
  }
  if(arg->getBalance() == -2) {
    if(arg->greater->getBalance() <= 0) {
      return arg->rotateLeft();
    } else {
      arg->greater = arg->greater->rotateRight();
      return arg->rotateLeft();
    }
  }
  return arg;
}
ValueTab::ValueTab(RedisKeyItem * key)    
    : key(key), ui(nullptr), isInitialized(false),
      tabMustBeDestroyed(false), operationInProgress(true)
{    
    setObjectName("valueTab");

    if (key == nullptr
            || key->getDbItem() == nullptr
            || key->getConnection() == nullptr) {
        return;
    }

    ui = QSharedPointer<ValueTabView>(new ValueTabView(key->text(), this));

    connect((QObject *)key->getDbItem(), SIGNAL(destroyed(QObject *)), this, SLOT(OnClose()));

    Command typeCmd = key->getTypeCommand();
    typeCmd.setOwner(this);
    typeCmd.setCallBackName("keyTypeLoaded");

    key->getConnection()->addCommand(typeCmd);

    /** Connect View SIGNALS to Controller SLOTS **/
    connect(ui->renameKey, SIGNAL(clicked()), this, SLOT(renameKey()));
    connect(ui->deleteKey, SIGNAL(clicked()), this, SLOT(deleteKey()));
    connect(ui.data(), SIGNAL(saveChangedValue(const QString&, const QModelIndex *)),
        this, SLOT(updateValue(const QString&, const QModelIndex *)));

    connect(this, SIGNAL(error(const QString&)), this, SLOT(errorOccurred(const QString&)));    

    isInitialized = true;
}
Example #5
0
void BasicHashTable::deleteEntry(unsigned index, TableEntry* entry) {
  TableEntry** ep = &fBuckets[index];

  Boolean foundIt = False;
  while (*ep != NULL) {
    if (*ep == entry) {
      foundIt = True;
      *ep = entry->fNext;
      break;
    }
    ep = &((*ep)->fNext);
  }

  if (!foundIt) { // shouldn't happen
#ifdef DEBUG
    fprintf(stderr, "BasicHashTable[%p]::deleteEntry(%d,%p): internal error - not found (first entry %p", this, index, entry, fBuckets[index]);
    if (fBuckets[index] != NULL) fprintf(stderr, ", next entry %p", fBuckets[index]->fNext);
    fprintf(stderr, ")\n");
#endif
  }

  --fNumEntries;
  deleteKey(entry);
  delete entry;
}
Example #6
0
int main()
{
  const int size(1000);
  for(int _i_ = 0; _i_ < 2000; _i_++) {
    int t[size], z(0);
    srand(time(0));
    ITNode<int>* head = new ITNode<int>(&z);
    for(int i = 1; i < size; i++) {
      //std::cout << *head << "\n---\n";
      t[i] = rand() % (2 * size);
      head = insertKey(head, t + i);
      if(!head->is_AVL())
      {
        std::cout << *head << "\n";
        return 255;
      }
    }
    for(int i = 1; i < size/2; i++) {
      int j = rand() % size;
      head = deleteKey(head, t + j);
      //std::cout << *head << "\n---\n";
      if(!head->is_AVL())
      {
        std::cout << *head << "\n";
        return 255;
      }
    }
    //std::cout << *head << "\n";
    delete(head);
    assert(voidNodeNr == 0);
    assert(keyNodeNr == 0);
//    std::cout << voidNodeNr << " " << keyNodeNr << "\n";
  }
}
int main(void) {
  struct tree *T = NULL, *result;
  int i;

  /* ??????? 10 ????? ? ?????????? ??????? */
  for (i = 0; i < 10; i++) {
    int ikey = (rand() % 20) + 1;
    printf("?????? ?? ??????? ? ???? %d \n", ikey);
    insertKey(ikey, "someinfo", &T);
  }

  printf("?????: ");

  printTree(T);
  printf("\n");

  /* ????????? ?? ???????? ? ???? 5 */
  result = search(5, T);
  printf("??????? ?: %s\n", result->info);

  /* ??????? ?????????? 10 ????? ?? ??????? */
  for (i = 0; i < 10; i++) {
    int ikey = (rand() % 20) + 1;
    printf("??????? ?? ???????? ? ???? %d \n", ikey);
    deleteKey(ikey, &T);
  }

  printf("?????: ");

  printTree(T);
  printf("\n");
  return 0;
}
//-----------------------------------------------------------------------------
void swftParaViewMenuBuilders::buildPipelineBrowserContextMenu(QWidget& widget)
{
  QString objectName = widget.objectName();
  Ui::pqPipelineBrowserContextMenu ui;
  ui.setupUi(&widget);
  // since the UI file tends to change the name of the menu.
  widget.setObjectName(objectName);
  widget.setContextMenuPolicy(Qt::ActionsContextMenu);

  QByteArray signalName=QMetaObject::normalizedSignature("deleteKey()");
  if (widget.metaObject()->indexOfSignal(signalName) != -1)
    {
    // Trigger a delete when the user requests a delete.
    QObject::connect(&widget, SIGNAL(deleteKey()),
      ui.actionPBDelete, SLOT(trigger()), Qt::QueuedConnection);
    }

  // And here the reactions come in handy! Just reuse the reaction used for
  // File | Open.
  new swftLoadModelReaction(ui.actionPBOpen);
  new pqChangePipelineInputReaction(ui.actionPBChangeInput);
  new pqCreateCustomFilterReaction(ui.actionPBCreateCustomFilter);
  new pqIgnoreSourceTimeReaction(ui.actionPBIgnoreTime);
  new pqDeleteReaction(ui.actionPBDelete);
  new pqCopyReaction(ui.actionPBCopy);
  new pqCopyReaction(ui.actionPBPaste, true);
}
void TimelineButton::update(double deltaTime){

    BasicButton::update(deltaTime);

    if (selectedKey){
        if (bSkeletalTrack){
            for (uint i=0;i<skeleton->bones.size();i++){
                selectedKey->boneMatrices[skeleton->bones[i]->name]=skeleton->bones[i]->transformMatrix;
                }
		}

		selectedKey->transformKey=connectedActor->transformMatrix;

        updateAction();
		deleteKey();
	}

    if (!interpolator.bFinished){
        if (bPlaying)
            interpolator.interpolate();
        }
    else{
        //don't destroy interpolator!
        interpolator.bFinished=false;
        bPlaying=false;
        }
}
Example #10
0
DWORD
TSHReg::DeleteKey(HKEY hkey, LPCTSTR pszSubKey)
{
  static TModuleProc2<DWORD,HKEY,LPCTSTR>
         deleteKey(GetModule(), DeleteKeyStr);
  return deleteKey(hkey,pszSubKey);
}
Example #11
0
T CPriorityHeap<T>::deleteMin() {

    T res = heap[0].key;

    deleteKey(heap[0].key);

    return res;
}
Example #12
0
CollData *CollDataCache::get(UCollator *collator, UErrorCode &status)
{
    char keyBuffer[KEY_BUFFER_SIZE];
    int32_t keyLength = KEY_BUFFER_SIZE;
    char *key = getKey(collator, keyBuffer, &keyLength);
    CollData *result = NULL, *newData = NULL;
    CollDataCacheEntry *entry = NULL, *newEntry = NULL;

    umtx_lock(&lock);
    entry = (CollDataCacheEntry *) uhash_get(cache, key);

    if (entry == NULL) {
        umtx_unlock(&lock);

        newData = new CollData(collator, key, keyLength, status);
        newEntry = new CollDataCacheEntry(newData);

        if (U_FAILURE(status) || newData == NULL || newEntry == NULL) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return NULL;
        }

        umtx_lock(&lock);
        entry = (CollDataCacheEntry *) uhash_get(cache, key);

        if (entry == NULL) {
            uhash_put(cache, newData->key, newEntry, &status);
            umtx_unlock(&lock);

            if (U_FAILURE(status)) {
                delete newEntry;
                delete newData;

                return NULL;
            }

            return newData;
        }
    }

    result = entry->data;
    entry->refCount += 1;
    umtx_unlock(&lock);

    if (key != keyBuffer) {
        deleteKey(key);
    }

    if (newEntry != NULL) {
        delete newEntry;
        delete newData;
    }

    return result;
}
Example #13
0
bool deleteKeyFromTree(TreePtr tree, LSQ_IntegerIndexT key){
    assert(tree != NULL && tree->root != NULL);
    TreeNodePtr rt = tree->root;
    if(!rt->keyCount) return false;

    int pos = getItemOrNext(rt, key);

    if(rt->keyCount != 1 || isLeaf(rt)) return deleteKey(rt, key, pos, true);

    assert(rt->nodes[0] != NULL && rt->nodes[1] != NULL);

    TreeNodePtr tmp = rt->nodes[0];
    bool res = deleteKey(rt, key, pos, true);
    if(!rt->keyCount){
        free(rt);
        tree->root = tmp;
        tmp->parent = NULL;
    }
    return res;
}
Example #14
0
bool deleteKey(TreeNodePtr node, LSQ_IntegerIndexT key, int pos, bool needFree){
//ALWAYS, on successful (with true on return) call of this function, we need to
//decrease .subtreeKeyCount; 
    bool res = true;
    if(NULL == node) return false;

//1
    if(isLeaf(node)){
        if(!isKeyFound(node, pos, key)) return false;
        excludeKey(node, pos, needFree);
        return true;
    }
//2
//if key found in internal node
    if(isKeyFound(node, pos, key)){
        //we always have left and right children of key splitter
        assert(node->nodes[pos] != NULL && node->nodes[pos + 1] != NULL);
        //we always have to free internal key
        assert(needFree);

        if(internalKeyDelete(node, pos, 0, FD_BY_RIGHT_SIDE)) return res;
        if(internalKeyDelete(node, pos, 1, FD_BY_LEFT_SIDE)) return res;
        
        //keyCounts left < t && right < t:
        mergeToLeft(node, pos);
        res = deleteKey(node->nodes[pos], key, t-1, needFree);
        if(res) node->subtreeKeyCount[pos]--;
        return res;
    }
//3: pivot/merge
    //key is not found yet and we don't need free it? FAIL. bad assert
    //assert(needFree && node->nodes[pos]->keyCount >= MIN_KEY_COUNT);

    pos = balanceNode(node, pos);

    assert(pos < node->childCount);
    res = deleteKey(node->nodes[pos], key, getItemOrNext(node->nodes[pos], key), needFree);
    if(res) node->subtreeKeyCount[pos]--;
    return res;

} //deleteKey
KeyListViewIface& KeyListPresenter::getView() {
	if (itsKeyListView == 0) {
		itsKeyListView = getFactory().createKeyListView();
		getView().getBtnAddKey().pressedSig.connect([=] {addKey();});
		getView().getBtnReload().pressedSig.connect(
				[=] {reloadKeyList();});
		getView().getBtnEditKey().pressedSig.connect([=] {editKey();});
		getView().getBtnDelKey().pressedSig.connect([=] {deleteKey();});
		getView().selectionChangedSig.connect([=](int pIdx){selectionChanged(pIdx);});
	}
	return *itsKeyListView;
}
Example #16
0
int main(){
	struct node* head = NULL;
	struct node* second = NULL;
	struct node* third = NULL;
	struct node* newnode = NULL;
	int key, ch, ch1;

	head = (struct node*)malloc(sizeof(struct node));
	second = (struct node*)malloc(sizeof(struct node));
	third = (struct node*)malloc(sizeof(struct node));
	
	head->data = 4;
	head->next = second;

    second->data = 5 ;
    second->next = third;

    third->data = 6;
    third->next = NULL;

    printf("\nOriginal List::\t\t");
    printList(head);

    ch1 = 0; 
    while(ch1 == 0){
			    printf("\nEnter choice::\n1.Insertion 2.Deletion 3. Exit::");
			    scanf("%d",&ch);
			    switch(ch){
				    case 1:
				    		printf("\nEnter key for Insertion::\t");
				    		scanf("%d", &key);
							printf("\nInsertion in beg::\t");
						    insertBeg(&head,key);
						    printList(head);
						    continue;

					case 2:
				    
						    printf("\nEnter key for Deletion::\t");
						    scanf("%d", &key);

						    printf("\nAfter Deletion::\t");
						    deleteKey(&head,key);
						    printList(head);
						    continue;

					case 3: 	ch1 = 1;
				}    
	}

	getchar();
	return 0;
}
GAESContext::~GAESContext()
{
    if(mAesKey) {
        CCCryptorFinal(mAesKey,NULL,0,NULL);
        CCCryptorRelease(mAesKey);
        mAesKey = NULL;
    }
    
	deleteKey();
	memset(mRawKey, 0, MAX_AES_KEY_BITS / 8);
	mInitFlag = false;
}
Example #18
0
int main()
{
    char keys[][8] = {"she", "sells", "sea", "shore", "the", "by", "sheer"};
    trie_t trie; 
    initialize(&trie);
 
    for(int i = 0; i < ARRAY_SIZE(keys); i++){
        insert(&trie, keys[i]);
    }
    deleteKey(&trie, keys[0]); 
    printf("%s %s\n", "sea", search(&trie, "sea") ? "Present in trie" : "Not present in trie"); 
    return 0;
}
Example #19
0
/* set "OFFSET var" for next cursor iteration */
void incrOffsetVar(redisClient *c, cswc_t *w, long incr) {
    robj *ovar = createStringObject(w->ovar, sdslen(w->ovar));
    if (w->lim > incr) {
        deleteKey(c->db, ovar);
    } else {
        lolo  value = (w->ofst == -1) ? (lolo)incr :
                                        (lolo)w->ofst + (lolo)incr;
        robj *val   = createStringObjectFromLongLong(value);
        int   ret   = dictAdd(c->db->dict, ovar, val);
        if (ret == DICT_ERR) dictReplace(c->db->dict, ovar, val);
    }
    server.dirty++;
}
Example #20
0
// delete the node which contain the minimum value and return the minimum value
Priority BinaryHeap :: extractMin()
{
  Priority datakey =root->key;
  if(root==NULL)
    {
      cout<<"INVALID OPERATION\n";
      return -1;
    }
  else{
    deleteKey(root);
  }
  return datakey;
}
Example #21
0
//Cormen: 2a-2b
bool internalKeyDelete(TreeNodePtr node, int pos, int shift, FallDownBehave fb){
    int childNodePos = pos + shift;
    TreeNodePtr child = node->nodes[childNodePos];
    if(childNodePos >= node->childCount || child->keyCount < t) return false;

    free(node->items[pos]);
    node->items[pos] = fallDown(child, fb);
    
    LSQ_IntegerIndexT key = node->items[pos]->key;
    assert(deleteKey(child, key, getItemOrNext(child, key), false));
    node->subtreeKeyCount[childNodePos]--;

    return true;
}
Example #22
0
int
main(int argc, char *argv[])
{
    struct afsconf_dir *tdir;
    const char *confdir;

    if (argc == 1) {
	fprintf(stderr, "%s: usage is '%s <opcode> options, e.g.\n",
		argv[0], argv[0]);
	fprintf(stderr, "\t%s add <kvno> <keyfile> <princ>\n", argv[0]);
	fprintf(stderr, "\tOR\n\t%s add <kvno> <key>\n", argv[0]);
	fprintf(stderr, "\tOR\n\t%s add <type> <kvno> <subtype> <key>\n",
	        argv[0]);
	fprintf(stderr, "\tOR\n\t%s add <type> <kvno> <subtype> <keyfile> <princ>\n",
	        argv[0]);
	fprintf(stderr, "\t\tEx: %s add 0 \"80b6a7cd7a9dadb6\"\n", argv[0]);
	fprintf(stderr, "\t%s delete <kvno>\n", argv[0]);
	fprintf(stderr, "\t%s list\n", argv[0]);
	exit(1);
    }

    confdir = AFSDIR_SERVER_ETC_DIRPATH;

    tdir = afsconf_Open(confdir);
    if (!tdir) {
	fprintf(stderr, "%s: can't initialize conf dir '%s'\n", argv[0],
		confdir);
	exit(1);
    }
    if (strcmp(argv[1], "add")==0) {
	addKey(tdir, argc, argv);
    }
    else if (strcmp(argv[1], "delete")==0) {
	deleteKey(tdir, argc, argv);
    }
    else if (strcmp(argv[1], "list") == 0) {
	listKey(tdir, argc, argv);

    }
    else {
	fprintf(stderr, "%s: unknown operation '%s', type '%s' for "
		"assistance\n", argv[0], argv[1], argv[0]);
	exit(1);
    }
    exit(0);
}
/* 
 * Standard CSPContext init, called from CSPFullPluginSession::init().
 * Reusable, e.g., query followed by en/decrypt.
 */
void CastContext::init( 
	const Context &context, 
	bool encrypting)
{
	if(mInitFlag && !opStarted()) {
		return;
	}

	CSSM_SIZE	keyLen;
	uint8 		*keyData = NULL;
	bool		sameKeySize = false;
	
	/* obtain key from context */
	symmetricKeyBits(context, session(), CSSM_ALGID_CAST, 
		encrypting ? CSSM_KEYUSE_ENCRYPT : CSSM_KEYUSE_DECRYPT,
		keyData, keyLen);
	if((keyLen < kCCKeySizeMinCAST) || (keyLen > kCCKeySizeMaxCAST)) {
		CssmError::throwMe(CSSMERR_CSP_INVALID_ATTR_KEY);
	}
	
	/*
	 * Delete existing key if key size changed
	 */
	if(mRawKeySize == keyLen) {
		sameKeySize = true;
	}
	else {
		deleteKey();
	}

	/* init key only if key size or key bits have changed */
	if(!sameKeySize || memcmp(mRawKey, keyData, mRawKeySize)) {
        (void) CCCryptorCreateWithMode(0, kCCModeECB, kCCAlgorithmCAST, ccDefaultPadding, NULL, keyData, keyLen, NULL, 0, 0, 0, &mCastKey);
	
		/* save this raw key data */
		memmove(mRawKey, keyData, keyLen); 
		mRawKeySize = (uint32)keyLen;
	}
	
	/* Finally, have BlockCryptor do its setup */
	setup(kCCBlockSizeCAST, context);
	mInitFlag = true;
}	
Example #24
0
/* 
 * Standard CSPContext init, called from CSPFullPluginSession::init().
 * Reusable, e.g., query followed by en/decrypt.
 */
void BlowfishContext::init( 
	const Context &context, 
	bool encrypting)
{
	if(mInitFlag && !opStarted()) {
		return;
	}

	CSSM_SIZE	keyLen;
	uint8 		*keyData = NULL;
	bool		sameKeySize = false;
	
	/* obtain key from context */
	symmetricKeyBits(context, session(), CSSM_ALGID_BLOWFISH, 
		encrypting ? CSSM_KEYUSE_ENCRYPT : CSSM_KEYUSE_DECRYPT,
		keyData, keyLen);
	if((keyLen < BF_MIN_KEY_SIZE_BYTES) || (keyLen > BF_MAX_KEY_SIZE_BYTES)) {
		CssmError::throwMe(CSSMERR_CSP_INVALID_ATTR_KEY);
	}
	
	/*
	 * Delete existing key if key size changed
	 */
	if(mRawKeySize == keyLen) {
		sameKeySize = true;
	}
	else {
		deleteKey();
	}

	/* init key only if key size or key bits have changed */
	if(!sameKeySize || memcmp(mRawKey, keyData, mRawKeySize)) {
		BF_set_key(&mBfKey, (int)keyLen, keyData);
	
		/* save this raw key data */
		memmove(mRawKey, keyData, keyLen); 
		mRawKeySize = (unsigned int)keyLen;
	}
	
	/* Finally, have BlockCryptor do its setup */
	setup(BF_BLOCK, context);
	mInitFlag = true;
}	
Example #25
0
int deleteItem(char *code){

  struct Node found;
  struct Node root;
  int index;

  getNode(0, &root);

  index = search(&root, code, &found);

  if(index == -1){
    printf("ERROR: Item with code %s is not in database.\n", code);
    return 0;
  }

  deleteKey(&found, code);

  return 0;
}
Example #26
0
int main()
{
	avltree *tree;

	/*tree = mkNode( 5, 5,
	               mkNode( 3, 3,
	                       mkNode( 1, 1,
	                               NULL,
	                               mkNode( 4, 4, NULL, NULL)),
	                       NULL),
	               NULL);*/

	//printBinTree( tree);
	//freeBinTree( tree);

	tree = NULL;
	tree = insertKey( 9,1,tree);
	tree = insertKey( 5,1,tree);
	tree = insertKey( 10,1,tree);
	tree = insertKey( 0,1,tree);
	tree = insertKey( 6,1,tree);
	tree = insertKey( 11,1,tree);
	tree = insertKey(-1,1,tree);
	tree = insertKey(1,1,tree);
	tree = insertKey(2,1,tree);
	tree = deleteKey(10,tree);


	//tree = deleteKey(20,tree);
	printBinTree(tree);
	//tree = deleteKey( 5, tree);
	//printBinTree( tree);

	printf( "Value for key 10: %d\n", findKey( 10, tree));
	printf( "Value for key 20: %d\n", findKey( 20, tree));

	freeBinTree( tree);
	return 0;
}
int main() {
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for (i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {insert(key); np++; size++;}
    else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') deleteFirst();
        else if (com[6] == 'L') deleteLast();
      } else {
        deleteKey(key); nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}
bool KeystoreClientImpl::createOrVerifyAuthenticationKey(const std::string& key_name) {
    bool key_exists = doesKeyExist(key_name);
    if (key_exists) {
        bool verified = false;
        if (!verifyAuthenticationKeyAttributes(key_name, &verified)) {
            return false;
        }
        if (!verified) {
            auto result = deleteKey(key_name);
            if (!result.isOk()) {
                ALOGE("Failed to delete invalid authentication key: %d", int32_t(result));
                return false;
            }
            key_exists = false;
        }
    }
    if (!key_exists) {
        AuthorizationSetBuilder key_parameters;
        key_parameters.HmacKey(kHMACKeySize)
            .Digest(Digest::SHA_2_256)
            .Authorization(TAG_MIN_MAC_LENGTH, kHMACOutputSize)
            .Authorization(TAG_NO_AUTH_REQUIRED);
        AuthorizationSet hardware_enforced_characteristics;
        AuthorizationSet software_enforced_characteristics;
        auto result =
            generateKey(key_name, key_parameters, &hardware_enforced_characteristics,
                        &software_enforced_characteristics);
        if (!result.isOk()) {
            ALOGE("Failed to generate authentication key: %d", int32_t(result));
            return false;
        }
        if (hardware_enforced_characteristics.size() == 0) {
            ALOGW("WARNING: Authentication key is not hardware-backed.");
        }
    }
    return true;
}
bool KeystoreClientImpl::createOrVerifyEncryptionKey(const std::string& key_name) {
    bool key_exists = doesKeyExist(key_name);
    if (key_exists) {
        bool verified = false;
        if (!verifyEncryptionKeyAttributes(key_name, &verified)) {
            return false;
        }
        if (!verified) {
            auto result = deleteKey(key_name);
            if (!result.isOk()) {
                ALOGE("Failed to delete invalid encryption key: %d", int32_t(result));
                return false;
            }
            key_exists = false;
        }
    }
    if (!key_exists) {
        AuthorizationSetBuilder key_parameters;
        key_parameters.AesEncryptionKey(kAESKeySize)
            .Padding(PaddingMode::PKCS7)
            .Authorization(TAG_BLOCK_MODE, BlockMode::CBC)
            .Authorization(TAG_NO_AUTH_REQUIRED);
        AuthorizationSet hardware_enforced_characteristics;
        AuthorizationSet software_enforced_characteristics;
        auto result =
            generateKey(key_name, key_parameters, &hardware_enforced_characteristics,
                        &software_enforced_characteristics);
        if (!result.isOk()) {
            ALOGE("Failed to generate encryption key: %d", int32_t(result));
            return false;
        }
        if (hardware_enforced_characteristics.size() == 0) {
            ALOGW("WARNING: Encryption key is not hardware-backed.");
        }
    }
    return true;
}
// ************************************************************ 
void
testDelete (void)
{
  RID insert[] = { 
    {1,1},
    {2,3},
    {1,2},
    {3,5},
    {4,4},
    {3,2}, 
  };
  int numInserts = 6;
  Value **keys;
  char *stringKeys[] = {
    "i1",
    "i11",
    "i13",
    "i17",
    "i23",
    "i52"
  };
  testName = "test b-tree inserting and search";
  int i, iter;
  BTreeHandle *tree = NULL;
  int numDeletes = 3;
  bool *deletes = (bool *) malloc(numInserts * sizeof(bool));
  
  keys = createValues(stringKeys, numInserts);

  // init
  TEST_CHECK(initIndexManager(NULL));

  // create test b-tree and randomly remove entries
  for(iter = 0; iter < 50; iter++)
    {
      // randomly select entries for deletion (may select the same on twice)
      for(i = 0; i < numInserts; i++)
	deletes[i] = FALSE;
      for(i = 0; i < numDeletes; i++)
	deletes[rand() % numInserts] = TRUE;

      // init B-tree
      TEST_CHECK(createBtree("testidx", DT_INT, 2));
      TEST_CHECK(openBtree(&tree, "testidx"));

      // insert keys
      for(i = 0; i < numInserts; i++)
	TEST_CHECK(insertKey(tree, keys[i], insert[i]));
      
      // delete entries
      for(i = 0; i < numInserts; i++)
	{
	  if (deletes[i])
	    TEST_CHECK(deleteKey(tree, keys[i]));
	}

      // search for keys
      for(i = 0; i < 1000; i++)
	{
	  int pos = rand() % numInserts;
	  RID rid;
	  Value *key = keys[pos];
	  
	  if (deletes[pos])
	    {
	      int rc = findKey(tree, key, &rid);
	      ASSERT_TRUE((rc == RC_IM_KEY_NOT_FOUND), "entry was deleted, should not find it");
	    }
	  else
	    {
	      TEST_CHECK(findKey(tree, key, &rid));
	      ASSERT_EQUALS_RID(insert[pos], rid, "did we find the correct RID?");
	    }
	}

      // cleanup
      TEST_CHECK(closeBtree(tree));
      TEST_CHECK(deleteBtree("testidx"));
    }

  TEST_CHECK(shutdownIndexManager());
  freeValues(keys, numInserts);
  free(deletes);

  TEST_DONE();
}