Created
March 7, 2014 15:47
-
-
Save ppat/9413946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* interleave slots so that slots of different nodes are given priority during assignment of topology as opposed to slots of the same node */ | |
private def interleaveSlotsByNode(slots: Set[WorkerSlot]): List[WorkerSlot] = { | |
val groupedSeq = slots.groupBy(_.getNodeId).toSeq | |
val slotsByNode = mutable.Map[String, Set[WorkerSlot]](groupedSeq: _*) | |
val nodes = slotsByNode.keys.toList.sorted | |
val results = mutable.ListBuffer[WorkerSlot]() | |
while (!slotsByNode.isEmpty) { | |
for (node <- nodes) { | |
slotsByNode.get(node) match { | |
case Some(slots) => { | |
val firstSlot = slots.head | |
results += firstSlot | |
val remaining = slots - firstSlot | |
if (remaining.isEmpty) | |
slotsByNode.remove(node) | |
else | |
slotsByNode.put(node, remaining) | |
} | |
case None => {} | |
} | |
} | |
} | |
results.toList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment