As parent said, items with the same name stack together, items with different names don't. There are item testers in minecraft based on whether the item will stack.
I can see several ways that you could implement storage and processing using that, thank you.
For anyone else thinking about the problem, there are two processes that could be used by item sorting to do processing:
1. You can use the stream of items through a pipeline (if deterministic enough) to encode a bit of strings. You can do this without enchanting, because you only need two item types.
2. You initialize an instruction decoder and have it sort the item based on type, which then triggers a command block to decode the instruction further.