1
0
mirror of https://github.com/CPunch/Laika.git synced 2024-11-21 20:40:05 +00:00

laikaC_iterPeers now uses hashmap_iter

TODO:
- refactor codebase to use laikaC_iterPeersNext instead of laikaC_iterPeers where appropriate
This commit is contained in:
CPunch 2022-08-02 11:22:06 -05:00
parent 10a36df090
commit 68f8e80c75

View File

@ -451,28 +451,25 @@ void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_tas
/* =======================================[[ Peer Iter ]]======================================= */ /* =======================================[[ Peer Iter ]]======================================= */
struct sWrapperData bool laikaC_iterPeersNext(struct sLaika_cnc *cnc, size_t *i, struct sLaika_peer **peer)
{ {
tLaika_peerIter iter; tCNC_PeerHashElem *elem;
void *uData;
};
/* wrapper iterator */ if (hashmap_iter(cnc->peers, i, (void *)&elem)) {
bool iterWrapper(const void *rawItem, void *uData) *peer = elem->peer;
{ return true;
struct sWrapperData *data = (struct sWrapperData *)uData; }
tCNC_PeerHashElem *item = (tCNC_PeerHashElem *)rawItem;
return data->iter(item->peer, data->uData); *peer = NULL;
return false;
} }
void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData) void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData)
{ {
struct sWrapperData wrapper; size_t i = 0;
wrapper.iter = iter; struct sLaika_peer *peer;
wrapper.uData = uData;
/* iterate over hashmap calling our iterWrapper, pass the *real* iterator to /* call iter for every peer in cnc->peers */
itemWrapper so that it can call it. probably a better way to do this while (laikaC_iterPeersNext(cnc, &i, &peer))
but w/e lol */ iter(peer, uData);
hashmap_scan(cnc->peers, iterWrapper, &wrapper);
} }