Michael D. Coogan, The Old Testament: A Literary and Historical Introduction to the Hebrew Scriptures, third edition (OUP, 2014), 62.
In Genesis 4, we have a genealogy from Adam to Enosh, which is interrupted by a lengthy story about Cain and Abel and shorter stories about Cain’s descendants, especially Lamech. The genealogy concludes with the statement that it was then that Yahweh was first worshiped. Most of the chapter is devoted to Cain, but at its end, we find a shift to Seth, the son born to Eve as a replacement for Abel. This is what is called a branching or segmented genealogy, which traces several groups of descendants from a common ancestor. The J genealogy in parts of Genesis 10, the “table of nations”… is of the same type and also includes a digression, about Nimrod.
J and P derive from different traditions. The names Lamech and Enoch occur in the line of Cain in J (Gen. 4.17-18), but in that of Seth in P (5.18, 25). Although some of the names are the same, others have different forms, like that of the father of Lamech, Methushael in J (4.18) but Methuselah in P (5.21).