Completed

Analyze lists using bash scrip

This project was successfully completed by kaloyan13 for $40 USD in 2 days.

Get free quotes for a project like this
Employer working
Completed by:
Skills Required
Project Budget
$30-$50 USD
Completed In
2 days
Total Bids
5
Project Description

I Need a bash script that does the following:

step 1: parse

You are given 2 lists of strings.
In the first list each entry has the following format:
@protocol protocolName

we will define a hashmap
var protocolToSuperProtocols = new hashmap<string, set>

protocolToSuperProtocols should contain all protocolNames as keys, and a list of implementedProtocol as the values.
* Ignore any trailing spaces
* if an implementedProtocol appears more than once, add it only one

Example:

@protocol p1
@protocol p2
@protocol p4

will output:

protocolToSuperProtocols='([p1]="p2,p3" , [p2]="", [p4]="p5" )'


The second list contains the following entries:
@interface className : superClass

the entries must have className but superClass and implementedProtocol list are optional.

lets define two hashMaps:

var classToSuperClass = new hashmap
var classToProtocols = new hashmap<string, set>

classToSuperClass will contain className as key and superClass as value
* if a class does not have a superclass, ignore the entry
* a class will have only one superclass
* ignore spaces

classToProtocols will contain className as key and the list of implementedProtocol as value
* if a class has implementedProtocol it will always have a super class
* if a class does not have implementedProtocol list, leave blank
* if a value repeats itself in implementedProtocol list, add it only once
* ignore spaces

example:

@interface A : B
@interface B : C
@interface D
@interface C : D

will output:

classToSuperClass ='([A]="B" , [B]="C", [C]="D", [D]="" )'
classToProtocols ='([A]="" , [B]="p1,p2,p3", [C]="p1,p4", [D]="" )'

step 2: processing

we will define our result datastructure:

var protocolToImps = new hashmap<string, set >

do the following:

for (classToSuperClass as (className => superClass)) {
travereOverClassHierarchAndAct(className);
}
echo protocolToImps;

function travereOverClassHierarchAndAct(className) {
if (className == null) return;
implementingProtocols = classToProtocols[className];
addBindToResultList(className, implementingProtocols);
superClass = classToSuperClass[className];
travereOverClassHierarchAndAct(superClass)
}

function addBindToResultList(classname, protocolList) {
if (protocolList == null) return;
for (implementingProtocols as protocol) {
protocolToImps[protocol] += className;
addBindToResult(className, protocolToSuperProtocols[protocol] );
}
}


the following should output (for the above dataset):

protocolToImps ='([p1]="A,B,C",[p2]="A,B,C",[p3]="A,B,C",[p4]="A,B,C",[p5]="A,B,C")'


*Please not that == null means empty list or undefined key
*There should be not circular dependencies in the data set
*Please use bash 4 with associative arrays and test for bash script version in the beginning of the script

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online