Analyze lists using bash scrip

完了済み 投稿 Feb 18, 2013 着払い
完了済み 着払い

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

マックOS シェルスクリプト

プロジェクトID: #4256753

プロジェクトについて

4個の提案 リモートプロジェクト アクティブ Feb 27, 2013

アワード:

kaloyan13

Bash programmer.

$40 USD 2日以内
(281レビュー)
7.0

4人のフリーランサーが、平均$55 で、この仕事に入札しています。

gyaseen1986

Hi there, i am very interested to complete this project. please see my past reviews lets complete this project

$50 USD 3日以内
(17件のレビュー)
4.6
srinichal

Ready to discuss further

$80 USD 3日以内
(8件のレビュー)
4.3
mantzoun

I've been using bash scripts in my work extensively for the past 6 years, so this project shouldn't be any problem. However I will need additional clarifications, because it is not clear to me in the examples you pr もっと

$50 USD 3日以内
(0件のレビュー)
0.0