Towards Understanding the Mechanism of Contrastive Learning via Similarity Structure: A Theoretical Analysis