CouchDB Directional Acyclic Graph (DAG)

If my structure looks like this:

[{Name: 'A', Depends: []},
{Name: 'B', Depends: ['A']},
{Name: 'C', Depends: ['A']},
{Name: 'D', Depends: ['C']},
{Name: 'E', Depends: ['D','B']}]

How can I write a map and reduce functions so that my result:

[{Key: 'A', Value: []},
{Key: 'B', Value: ['A']},
{Key: 'C', Value: ['A']},
{Key: 'D', Value: ['A','C']}
{Key: 'E', Value: ['D','B','C','A']}]

I get that the map function should call its dependencies, but I don’t know how to reduce them so that they can be applied further down the tree without throwing performance out of the window and expecting all the mappings. I also cannot use paths because there is not always a unique path (for example, D A-> C-> D or A-> D).

+3
source share
2 answers

If this is really about javascript, then I guess you don't have much choice.

, : http://www.electricmonk.nl/log/2008/08/07/dependency-resolving-algorithm/

( ) .

Array.map() .

0

couchdb, "complete_dependencies". node.

{: 'D', CompleteDepends: ['C', 'A']}

db "" , , . :

[{: 'C', Implies: 'D'}, {Name: 'A', Implies: 'D'}]

API , db. , db, . , . api . :

1) , _ db.

2) "" , . , . _, , complete_dependencies , "" .

, .

:

: {Name: 'A', Depends: []}. (1), , (2) .

{Name: 'B', Depends: ['A']}. "A" _dependencies db, , -. 'A', {Name: 'B', CompleteDepends: ['A']}. (2) , "B", .

{Name: 'C', Depends: ['A']} β†’ {Name: 'C', CompleteDepends: ['A']}.

{Name: 'D', Depends: ['C']}, , "C" "A" ,

{: 'D', CompleteDepends: ['C', 'A']}

: "A" , C "CompleteDependencies", A C .

{Name: 'E', Depends: ['D', 'B']}, 'D' 'B' , , D complete C A B A. {Name: 'E', CompleteDepends: ['D', 'B', 'C', 'A']}.

, "A" : {Name: 'A', Depends: ['Z']}.

1) "A" β†’ {Name: 'A', CompleteDepends: ['Z']}

2) , "A" . B, C, D, E.

. , C: {Name: 'C', Depends: ['Z']}.

(1) {Name: 'C', CompleteDepends: ['Z']}.

, C, D E. , E, , D, D C, D. , (2) .

, "" "" , "" .

0

Source: https://habr.com/ru/post/1765386/


All Articles