There are a few approaches you could consider depending on who/what needs to know the past state.
First, it should be fairly obvious that miners and full nodes are fully aware of the state at any block height. They see the transactions and compute the state themselves. This doesn't mean past states are conveniently accessible inside contract logic.
Contract logic is geared toward current state, which is usually the most important. Get variable state at specific block number
When you say "I want to", it's unclear if you need the contract to access past states, or clients. Clients can observe event logs and compute past states. That is, if the smart contract author uses them appropriately. In my opinion, a good application of event logs is to create an audit trail that will make it possible for a client to reconstruct the state history of the contract.
I stress "possible" because immutable code in smart contracts implies that we should aim to keep it as simple as possible. Generally, don't clutter it up with too many client-side concerns.
Here's your contract with the logs added.
pragma solidity ^0.4.18;
contract RegisterContract {
uint public contractWeight;
mapping(bytes32=>string) public contracts;
bytes32[] public myHashes;
event LogAddContract(address sender, bytes32 hashKey, string jsonInput);
event LogAddWeight(address sender, uint weight);
function addContract ( string jsonInput, bytes32 hashKey) public {
contracts[hashKey] = jsonInput;
myHashes.push(hashKey);
LogAddContract(msg.sender, hashKey, jsonInput);
}
function addWeight (uint weight) public {
contractWeight = weight;
LogAddWeight(msg.sender, weight);
}
function () payable public {
}
}
I have seen an experimental project using assember to explore event logs from inside a contract. Other than that, event logs are generally out of reach for contract logic.
With a dependable state and an observable state history you might ask yourself why (or if) the contract really needs to look into the past. I haven't seen too many cases where this is actually needed.
If you do find that there is truly a need for an in-state history, then you will have to create it yourself and append records as you go.
Hope it helps.