The exact inner workings of the splitter
Posted: Wed May 21, 2014 10:11 am
During a recent discussion in one of the many splitter-suggestion threads it has become clear that the exact splitter functionality is not quite as simple as it seems at first glance. Since it was off-topic in that thread, I'm making a new one to discuss the exact algorithm that the splitter uses.
At first glance it might seem that the splitter simply alternates between the left and right output, for each input item. With only one type of item, this is what it does. Lets have a look:
A splitter with a balanced feed of 1 item type. Every other item goes to the other output belt. Items stay on the same lane
Because in this screenshot the input is perfectly balanced between the left and right lane, it seems as though the splitter splits the lanes: Items on the left lane go to the left output belt, items on the right lane go to the right output belt. This is just an illusion. Adding 1 single extra item to the input belt will make the output pattern switch around. (ToDo: add screenshot)
Now lets replace all items on the right half of the input belt with copper. If the splitter simple alternates between the left and right output belt we would expect all copper to go to the right belt, since that is where the iron plates went, that we replaced with copper.
The output pattern completely changes! Instead of sending items left - right - left - right, it now sends left - left - right - right. The splitter alternates each item type independently. If you only look at the copper, it goes left - right - left - right. If you only look at the iron it also goes left - right - left - right. If you look at both of them, it goes (iron)left - (copper)left - (iron)right - (copper)right.
If we add even more item types this becomes even clearer:
(Image by ssilk)
The first four items (one of each type) go to the right. The next four items go to the left.
One last image by ssilk:
Here we have two copper plates in each group, so the first plate goes to one side, the second plate to the other. The iron plates seem to go to the "wrong" side, but iron is actually the first item in each group of four. You can see that on the previous image.
Conclusion:
To me it seems the splitter has an internal state for each item type: Did the last item of that type go left, or right? The next item of that type is then sent to the other output belt.
Update:
The splitter also counts items, if one side of the splitter is blocked. Once that side is unblocked, it will receive up to 5 items before the other side starts receiving items again:
At first glance it might seem that the splitter simply alternates between the left and right output, for each input item. With only one type of item, this is what it does. Lets have a look:
A splitter with a balanced feed of 1 item type. Every other item goes to the other output belt. Items stay on the same lane
Because in this screenshot the input is perfectly balanced between the left and right lane, it seems as though the splitter splits the lanes: Items on the left lane go to the left output belt, items on the right lane go to the right output belt. This is just an illusion. Adding 1 single extra item to the input belt will make the output pattern switch around. (ToDo: add screenshot)
Now lets replace all items on the right half of the input belt with copper. If the splitter simple alternates between the left and right output belt we would expect all copper to go to the right belt, since that is where the iron plates went, that we replaced with copper.
The output pattern completely changes! Instead of sending items left - right - left - right, it now sends left - left - right - right. The splitter alternates each item type independently. If you only look at the copper, it goes left - right - left - right. If you only look at the iron it also goes left - right - left - right. If you look at both of them, it goes (iron)left - (copper)left - (iron)right - (copper)right.
If we add even more item types this becomes even clearer:
(Image by ssilk)
The first four items (one of each type) go to the right. The next four items go to the left.
One last image by ssilk:
Here we have two copper plates in each group, so the first plate goes to one side, the second plate to the other. The iron plates seem to go to the "wrong" side, but iron is actually the first item in each group of four. You can see that on the previous image.
Conclusion:
To me it seems the splitter has an internal state for each item type: Did the last item of that type go left, or right? The next item of that type is then sent to the other output belt.
Update:
The splitter also counts items, if one side of the splitter is blocked. Once that side is unblocked, it will receive up to 5 items before the other side starts receiving items again: