Exemplo n.º 1
0
void deleteNode(char* alias, Node** head)
{
	Node* cur=*head;
	if(compareAlias(((*head)->data)->als, alias)!=0)
	{
		while((cur->next!=NULL)&&(compareAlias((cur->data)->als, alias)!=0))
			cur=cur->next;
		if(cur->next==NULL)
			printf("%s: not found\n", alias);
		else
		{
			
			Node* temp=cur->next;
			cur->next=cur->next->next;
			cleanNode(temp);
		}
	}
	else
	{
		*head=cur->next;
		cleanNode(cur);
	}	
	

}
Exemplo n.º 2
0
void clearList(Node** head)
{
	Node* cur= *head;
	
	while(cur!=NULL)
	{
		*head=cur->next;
		cleanNode(cur);
		cur=*head;
	}
	

}
Exemplo n.º 3
0
void initNode(struct inode** n, size_t sz) {
    *n = (struct inode*) malloc(sz);
    cleanNode(*n);
}
Exemplo n.º 4
0
void bTree::deleteNode(unsigned int parent, unsigned int path){
    findPath.pop_back();

    unsigned int i;
    bTreeNode cur = assignNode(parent);

    cur.dirty = true;
    Index backupInd;
    backupInd = cur.indexList.front();
    if (path > 0)
        cur.indexList.erase(cur.indexList.begin()+path-1);
    else
        cur.indexList.erase(cur.indexList.begin()+path);
    cur.ptrList.erase(cur.ptrList.begin()+path);
    cur.valNum--;

    if(cur.type != ROOT && cur.valNum+1<(cur.maxNum+2)/2)
    {
        bTreeNode left,right;
        unsigned int path = findPath.back();
        bTreeNode temp = findBro(cur);
        if(temp.type == INIT)
        {
            freeNode(cur);
            return;
        }
        if(temp.indexList.front()<backupInd)
        {
            left = temp;
            right = cur;
        }
        else
        {
            left = cur;
            right = temp;
            path++;
        }
        left.dirty = true;
        right.dirty = true;
        if(left.valNum + right.valNum + 2 <= left.maxNum + 1)
        {
            left.indexList.push_back(findMinIndex(right));
            unsigned int i;
            for (i = 0; i < right.valNum; ++i)
            {
                left.indexList.push_back(right.indexList[i]);
                left.ptrList.push_back(right.ptrList[i]);
                bTreeNode temp = assignNode(right.ptrList[i]);
                temp.dirty = true;
                temp.parentPtr = left.blockNo;
                freeNode(temp);
            }
            left.ptrList.push_back(right.ptrList.back());
            bTreeNode temp = assignNode(right.ptrList.back());
            temp.dirty = true;
            temp.parentPtr = left.blockNo;
            freeNode(temp);
            left.valNum+=right.valNum+1;
            freeNode(left);
            cleanNode(right);
            deleteNode(right.parentPtr,path);
        }
        else
        {
            unsigned int half = (left.valNum + right.valNum + 2) / 2;
            unsigned int i;
            right.indexList.insert(right.indexList.begin(),findMinIndex(right));
            for (i = left.valNum+1; i < half; ++i)
            {
                left.indexList.push_back(right.indexList.front());
                left.ptrList.push_back(right.ptrList.front());
                left.valNum++;
                right.ptrList.erase(right.ptrList.begin());
                right.indexList.erase(right.indexList.begin());
                right.valNum--;
                bTreeNode temp = assignNode(left.ptrList.back());
                temp.dirty = true;
                temp.parentPtr = left.blockNo;
                freeNode(temp);
            }
            for (i = left.valNum; i >= half; --i)
            {
                right.indexList.insert(right.indexList.begin(),left.indexList.back());
                right.ptrList.insert(right.ptrList.begin(),left.ptrList.back());
                right.valNum++;
                left.ptrList.erase(left.ptrList.end());
                left.indexList.erase(left.indexList.end());
                left.valNum--;
                bTreeNode temp = assignNode(right.ptrList.front());
                temp.dirty = true;
                temp.parentPtr = right.blockNo;
                freeNode(temp);
            }
            right.indexList.erase(right.indexList.begin());
            bTreeNode temp = assignNode(right.parentPtr);
            temp.dirty = true;
            temp.indexList[path-1] = findMinIndex(right);
            freeNode(temp);
            freeNode(left);
            freeNode(right);
        }
    }
    else if(cur.type==ROOT&&cur.valNum==0)
    {
        bTreeNode temp = assignNode(cur.ptrList.front());
        if(temp.type == LEAF)
        {
            freeNode(temp);
            freeNode(cur);
            return;
        }
        temp.dirty = true;
        temp.type = ROOT;
        temp.parentPtr = 0;
        cleanNode(cur);
        freeNode(temp);
        root = temp.blockNo;
    }
    else
        freeNode(cur);
    return;
}
Exemplo n.º 5
0
void bTree::deleteIndex(Index ind){
    unsigned int i;
    bTreeNode cur = findFirstNode(ind);

    for (i = 0; i < cur.valNum; ++i)
    {
        if (ind<=cur.indexList[i] && ind>=cur.indexList[i])
            break; 
    }
    if(i == cur.valNum)
        return;
    cur.dirty = true;
    cur.indexList.erase(cur.indexList.begin()+i);
    cur.ptrList.erase(cur.ptrList.begin()+i);
    cur.valNum--;

    if(cur.type != ROOT && cur.valNum<(cur.maxNum+1)/2)
    {
        bTreeNode left,right;
        unsigned int path = findPath.back();
        bTreeNode temp = findBro(cur);
        if(temp.type == INIT)
        {
            freeNode(cur);
            return;
        }
        if(temp.indexList.front()<cur.indexList.front())
        {
            left = temp;
            right = cur;
        }
        else
        {
            left = cur;
            right = temp;
            path++;
        }
        left.dirty = true;
        right.dirty = true;
        if(left.valNum + right.valNum <= left.maxNum)
        {
            left.ptrList.pop_back();
            unsigned int i;
            for (i = 0; i < right.valNum; ++i)
            {
                left.indexList.push_back(right.indexList[i]);
                left.ptrList.push_back(right.ptrList[i]);
            }
            left.ptrList.push_back(right.ptrList.back());
            left.valNum+=right.valNum;
            freeNode(left);
            cleanNode(right);
            deleteNode(right.parentPtr,path);
        }
        else
        {
            unsigned int half = (left.valNum + right.valNum) / 2;
            unsigned int i;
            for (i = left.valNum; i < half; ++i)
            {
                left.indexList.push_back(right.indexList[i-left.valNum]);
                left.ptrList.insert(left.ptrList.end()-1,right.ptrList.back());
                left.valNum++;
                right.indexList.erase(right.indexList.begin());
                right.ptrList.erase(right.ptrList.begin());
                right.valNum--;
            }
            for (i = left.valNum-1; i >= half; --i)
            {
                right.indexList.insert(right.indexList.begin(),left.indexList.back());
                right.ptrList.insert(right.ptrList.begin(),left.ptrList[left.valNum-1]);
                right.valNum++;
                left.indexList.erase(left.indexList.end()-1);
                left.ptrList.erase(left.ptrList.end()-2);
                left.valNum--;
            }
            bTreeNode temp = assignNode(right.parentPtr);
            temp.dirty = true;
            temp.indexList[path-1] = right.indexList.front();
            freeNode(temp);
            freeNode(left);
            freeNode(right);
        }
    }
    else
        freeNode(cur);

    return;
}
Exemplo n.º 6
0
		void VDVSubscriptionService::_setFromParametersMap(const ParametersMap& map)
		{
			string content(map.getDefault<string>(PARAMETER_POST_DATA));

			XMLResults results;
			XMLNode allNode = XMLNode::parseString(content.c_str(), "AboAnfrage", &results);
			if(	results.error != eXMLErrorNone ||
				allNode.isEmpty()
			){
				_errorNumber = "100";
				_errorText = "Malformed XML";
				return;
			}

			try
			{
				string sender(allNode.getAttribute("Sender"));
				_client = &DataExchangeModule::GetVDVClient(sender);

				// Trace
				_client->trace("AboAnfrage", content);

				// Check if the client is declared as active
				if(!_client->get<Active>())
				{
					_errorNumber = "300";
					_errorText = "Sender is forbidden right now";
					return;
				}

				// Subscriptions cleaning
				XMLNode cleanNode(allNode.getChildNode("AboLoeschenAlle"));
				if(!cleanNode.isEmpty())
				{
					string cleanNodeStr(cleanNode.getText());
					if(	cleanNodeStr == "true" ||
						cleanNodeStr == "1"
					){
						_client->cleanSubscriptions();
					}
				}

				// New subscriptions
				size_t nbNodes(allNode.nChildNode("AboAZB"));
				for(size_t i(0); i<nbNodes; ++i)
				{
					XMLNode aboAZBNode(allNode.getChildNode("AboAZB", static_cast<int>(i)));
					string id(aboAZBNode.getAttribute("AboID"));
					if(id.empty())
					{
						continue;
					}

					boost::shared_ptr<VDVClientSubscription> subscription(new VDVClientSubscription(id, *_client));

					if(aboAZBNode.nChildNode("AZBID"))
					{
						XMLNode azbidNode(aboAZBNode.getChildNode("AZBID"));
						StopArea* stopArea(
							_client->get<DataSource>()->getObjectByCode<StopArea>(azbidNode.getText())
						);
						if(!stopArea)
						{
							continue;
						}
						subscription->setStopArea(stopArea);
					}

					if(aboAZBNode.nChildNode("LinienID"))
					{
						XMLNode linienNode(aboAZBNode.getChildNode("LinienID"));
						CommercialLine* line(
							_client->get<DataSource>()->getObjectByCode<CommercialLine>(linienNode.getText())
						);
						if(!line)
						{
							continue;
						}
						subscription->setLine(line);
					}

					// Direction filter
					if(aboAZBNode.nChildNode("RichtungsID"))
					{
						XMLNode linienNode(aboAZBNode.getChildNode("RichtungsID"));
						subscription->setDirectionFilter(linienNode.getText());
					}

					XMLNode durationNode(aboAZBNode.getChildNode("Vorschauzeit"));
					if(!durationNode.isEmpty())
					{
						try
						{
							time_duration timeSpan(
								minutes(
									lexical_cast<long>(durationNode.getText())
							)	);
							subscription->setTimeSpan(timeSpan);
						}
						catch(bad_lexical_cast&)
						{
						}
					}

					XMLNode hysteresisNode(aboAZBNode.getChildNode("Hysterese"));
					if(!hysteresisNode.isEmpty())
					{
						try
						{
							time_duration hysteresis(
								seconds(
									lexical_cast<long>(hysteresisNode.getText())
							)	);
							subscription->setHysteresis(hysteresis);
						}
						catch(bad_lexical_cast&)
						{
						}
					}
					
					_client->addSubscription(subscription);
				}

			}
			catch (Exception&)
			{
				_errorNumber = "200";
				_errorText = "Invalid sender";
				return;
			}

			// Error if the VDV server is inactive
			if(!DataExchangeModule::GetVDVServerActive())
			{
				_errorNumber = "400";
				_errorText = "Service temporary unavailable";
				return;
			}
		}