List of hanzi and their components I would like to be able to compute the distance between 2 hanzi according to their components.

My idea is that a hanzi like 式 is made of 工 and 弋. 2 hanzi are close if they share common components.

To be able to compute such distance, I need to be able to have a list of hanzi and their components in a digital format. Does such list exist?
I know exactly the thing. There's a project on Wikimedia commons to document the substructure of characters in terms of other characters. I haven't spent much time with the data itself, so I can't tell you how complete it is, but it seems pretty good based on my experience with the Tatoeba character search tool that is based on the data. That tool allows you to "explode" characters into their components (e.g., 蝴 =&gt; 月虫...) or search for all characters with a particular component (e.g., 隹 =&gt; 倠傕傩...).

Another project to do something similar is Wenlin's database of characters in the Character Description Language. Here is Wenlin's page of resources on the CDL. I'm not really sure if you have to buy Wenlin in order to get at some data. Anyhow, it looks pretty awesome.

Best of luck in your endeavors! I've wanted to do something similar, but I've always been too busy. Make sure to tell us about the cool things you do with the data :-)