Can I create a Linked list in Fortran only using ALLOCATABLE variables and not pointers? - linked-list

Can I create a Fortran Linked List without pointers in this way:
List:
TYPE Allocation_List
PRIVATE
CLASS(*), ALLOCATABLE :: Item
CLASS(Allocation_List), ALLOCATABLE :: Next
CONTAINS
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: IsItem => IsItem_AllocationList
PROCEDURE, PASS(self), PUBLIC :: SetItem => SetItem_AllocationList
PROCEDURE, PASS(self), PUBLIC :: GetItem => GetItem_AllocationList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: FreeItem => FreeItem_AllocationList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: IsNext => IsNext_AllocationList
PROCEDURE, PASS(self), PUBLIC :: SetNext => SetNext_AllocationList
PROCEDURE, PASS(self), PUBLIC :: GetNext => GetNext_AllocationList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: FreeNext => FreeNext_AllocationList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: Reset => Reset_AllocationList
PROCEDURE, PASS(self), PUBLIC :: Display => Display_AllocationListItem
END TYPE Allocation_List
Linked List:
TYPE Allocation_LinkedList
PRIVATE
CLASS(Allocation_List), ALLOCATABLE :: HeadList
CLASS(Allocation_List), ALLOCATABLE :: CurrList
CLASS(Allocation_List), ALLOCATABLE :: TailList
CONTAINS
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: IsSet => IsSet_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: Initiate => Initiate_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: Connect => Connect_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: GetCurr => GetCurrent_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: ForCurr => ForwardCurrent_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: DispCurr => DisplayCurrent_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: ResetCurr => ResetCurrent_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: Reset => Reset_AllocationLinkedList
PROCEDURE, PASS(self), PUBLIC, NON_OVERRIDABLE :: Display => Display_AllocationLinkedList
END TYPE Allocation_LinkedList
Will this List when used to create Linked List work? What may go wrong and are there any disadvantages? What are the advantages of Pointers over Allocatables?

The TailList of the Linked List should be a Pointer. The CurrList can be an ALLOCATABLE or POINTER.
The CurrList ALLOCATABLE has a disadvantage of 1) Reset to HeadList for every Connect and 2) Extra copy(memory) used to store part of Linked List under the CurrList.
Here is the implementation of Linked List using Allocatables and Pointers:
https://github.com/AkhilAkkapelli/DataStructures/tree/main/LinkedList

Related

how to parse only some comments using ANTLRv4

I devel application analyzing Java source code using ANTLRv4. I claim to match all single-line comments with first token TODO (e.g. // TODO <some-comment>) together with directly following statement.
Sample code:
class Simple {
public static void main(String[] args) {
// TODO develop cycle
for (int i = 0; i < 5; i++) {
// unmatched comment
System.out.println("hello");
}
// TODO atomic
int a;
// TODO revision required
{
int b = a+4;
System.out.println(b);
}
}
}
Result = map like this:
"develop cycle" -> for(...){...}
"atomic" -> int a
"revision required" -> {...}
Following official book (1) and similar topics on stackoverflow ((2), (3), (4), (5), (6)) I tried several ways.
At first I hoped for special COMMENTS channel as described in (1) and (2) but error rule 'LINE_COMMENT' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output occured.
I guess it would be much nicer to parse the source code in a way of ignoring all single-line comments BUT those beginning by TODO. I hope it is possible to add todo-comments directly into AST in order to use listeners/walkers. Than I'd only need register listener/walker for TODO comment and extract following statement, adding both to desired map.
I've been modifing official Java8 gammar for two days but without any success. Either compiler complains or AST is mismashed.
This is update I made:
// ...
COMMENT
: '/*' .*? '*/' -> skip
;
TODO_COMMENT
: '// TODO' ~[\r\n]*
;
LINE_COMMENT
: '//' ~[\r\n]* -> skip
;
Can anyone help me please? Grammars are not my cup of tea. Thanks in advance
EDIT1:
Grammar modification posted above complies without error, but following tree is generated (please note the red marked nodes including int)
EDIT2:
Assuming code sample above, while calling parser.compilationUnit(); following error is generated
line 3:2 extraneous input '// TODO develop cycle;' expecting {'abstract', 'assert', 'boolean', 'break', 'byte', 'char', 'class', 'continue', 'do', 'double', 'enum', 'final', 'float', 'for', 'if', 'int', 'interface', 'long', 'new', 'private', 'protected', 'public', 'return', 'short', 'static', 'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'try', 'void', 'while', IntegerLiteral, FloatingPointLiteral, BooleanLiteral, CharacterLiteral, StringLiteral, 'null', '(', '{', '}', ';', '<', '!', '~', '++', '--', '+', '-', Identifier, '#'}
line 8:2 extraneous input '// TODO atomic;' expecting {'abstract', 'assert', 'boolean', 'break', 'byte', 'char', 'class', 'continue', 'do', 'double', 'enum', 'final', 'float', 'for', 'if', 'int', 'interface', 'long', 'new', 'private', 'protected', 'public', 'return', 'short', 'static', 'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'try', 'void', 'while', IntegerLiteral, FloatingPointLiteral, BooleanLiteral, CharacterLiteral, StringLiteral, 'null', '(', '{', '}', ';', '<', '!', '~', '++', '--', '+', '-', Identifier, '#'}
line 11:2 extraneous input '// TODO revision required;' expecting {'abstract', 'assert', 'boolean', 'break', 'byte', 'char', 'class', 'continue', 'do', 'double', 'enum', 'final', 'float', 'for', 'if', 'int', 'interface', 'long', 'new', 'private', 'protected', 'public', 'return', 'short', 'static', 'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'try', 'void', 'while', IntegerLiteral, FloatingPointLiteral, BooleanLiteral, CharacterLiteral, StringLiteral, 'null', '(', '{', '}', ';', '<', '!', '~', '++', '--', '+', '-', Identifier, '#'}
So obviously grammar is incorect as it struggles with simple example
The reason is that you don't expect your special comment in any parser rule, i.e. no parser will match it.
You can do (at least) something of the following:
Add an optional TODO_COMMENT? in front of every parser rule.
Add the TODO_COMMENT token to a separate channel, e.g. ToDoCommentChannel (don't forget to define the constant for this channel!) and select each construct that follows a comment in tree-walking.
Rough outline of what I would do:
Use a separate channel for the TODO_COMMENTs.
lex and parse as usual
get all tokens from token stream and find those of the desired channel and get the following token on the default channel and store these in a list.
walk the parse and check for each entered rule if the starting token is in the list. If yes, copy the rules text to your result list, else recurse (if TODO_COMMENT can be nested, even recurse when the starting token is in the list).
UPDATE:
About the rule 'LINE_COMMENT' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output error:
This can be ignored since it only affects the interpreter like used by Antlrworks2 or the plugin. You can also do it like this:
//Instead of
TODO_COMMENT
: '// TODO' ~[\r\n]* -> channel(ToDoCommentChannel)
;
// do this (assuming the channel value is indeed 42):
TODO_COMMENT
: '// TODO' ~[\r\n]* -> channel(42 /*ToDoCommentChannel*/)
;
This will work in both Antlrworks2 and the code (you can still use the constant value for the channel in your java runtime code).

twitter-api: user token raises java.lang.NumberFormatException

project.clj
(defproject twit-api-learn "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[ring/ring-core "1.2.2"]
[ring/ring-jetty-adapter "1.2.2"]
[clj-http "0.9.2"]
[twitter-api "0.7.5"]])
core.clj
(ns twit-api-learn.core
(:use
[twitter.oauth]
[twitter.callbacks]
[twitter.callbacks.handlers]
[twitter.api.restful])
(:import
(twitter.callbacks.protocols SyncSingleCallback)))
(def my-creds (make-oauth-creds 0123456
0123456
012345-012345
0123456))
Error:
user=> (require 'twit-api-learn.core)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
CompilerException java.lang.NumberFormatException: Invalid number: 012345-012345, compiling:(twit_api_learn/core.clj:10:160)
So the error is being raised on the user token - the (fake) number 012345-012345. All of the "012345"s actually have their correct counterpart in core.clj.
Did I mention I'm new? :)
012345-012345 is indeed not a number, but the Clojure reader would try to treat it as one (before failing).
I don't see from the source of twitter-api what type that arg should have, but try making each argument a String, ie. "012345-012345", "0123456" ...

Neo4j exception when inserting data

I'm trying to insert bulk data into Neo4j using a script. After a while the script breaks with the following Exception.
PHP Fatal error: Uncaught exception 'Everyman\Neo4j\Exception' with message 'Unable to execute query [400]:
Headers: Array
(
[Content-Length] => 3031
[Content-Type] => application/json; charset=UTF-8
[Access-Control-Allow-Origin] => *
[Server] => Jetty(6.1.25)
)
Body: Array
(
[message] => An identifier is used with different types. The identifier ` UNNAMED2` is used both as Relationship and as Collection
[exception] => CypherTypeException
[fullname] => org.neo4j.cypher.CypherTypeException
[stacktrace] => Array
(
[0] => org.neo4j.cypher.internal.symbols.SymbolTable.add(SymbolTable.scala:33)
[1] => org.neo4j.cypher.internal.symbols.SymbolTable$$anonfun$checkNoOverlapsExist$1.apply(SymbolTable.scala:47)
[2] => org.neo4j.cypher.internal.symbols.SymbolTable$$anonfun$checkNoOverlapsExist$1.apply(SymbolTable.scala:46)
[3] => scala.collection.immutable.Map$Map1.foreach(Map.scala:109)
[4] => org.neo4j.cypher.internal.symbols.Symbol in phar:///var/www/zomato9/application/library/neo4jphp.phar/lib/Everyman/Neo4j/Command.php on line 116
The same query works from console and restarting the script from the same point where exception occurred works again for a while until it fails again. Catching the Exception and making the script sleep for few seconds does not break the script.
Any suggestions on what might be happening here?
UPDATE: Added a sample query
START a = node:?("?:?"), b = node:?("?:?")
MATCH a-[c1:ACTIVITY_LIST*]->z, z-[r1:ACTIVITY_LIST]->y
WHERE z.TIMESTAMP >= '.$time.' AND y.TIMESTAMP < '.$time.'
CREATE n = {?}, clist = {COMMENT_ID: ''}, a-[:IN_?]->n, n-[:OUT_?]->b, n-[:COMMENT_LIST]->clist, z-[:ACTIVITY_LIST]->n, n-[:ACTIVITY_LIST]->y
DELETE r1
RETURN n;

Google Reseller API returning "Resource already exists" on Insert Customer

Dear Google Engineers,
I keep trying to insert a customer and receive the following response:
[error] => Array
(
[errors] => Array
(
[0] => Array
(
[domain] => global
[reason] => duplicate
[message] => Resource already exists
)
)
[code] => 409
[message] => Resource already exists
)
I then go about attempting to retrieve the customer resource that supposedly exists via a GET request to https://www.googleapis.com/apps/reseller/v1/customers/{customerId} which fails to find the resource:
[error] => Array
(
[errors] => Array
(
[0] => Array
(
[domain] => global
[reason] => notFound
[message] => Not Found
)
)
[code] => 404
[message] => Not Found
)
Either I've uncovered a bug or the error response from POST https://www.googleapis.com/apps/reseller/v1/customers/ isn't nearly detailed enough for me to diagnose.
I've tried variations of the required fields with random values (addressLine1, alternateEmail, phoneNumber). I've also logged in to the Reseller CPanel and no matching customer exists for the domain.
If Google engineers care to try and diagnose internally, the customerId in question is ruby-stagingpop.co. You can email me to find out my Reseller account if necessary. Info in my profile.

FedEx 556 - No valid services available. when there should be

Hi I'm trying to use the wsdl api to get shipping cost calculated for my website.
I'm using opencart and this module (http://www.opencart.com/index.php?route=extension/extension/info&extension_id=2055&filter_search=fedex&sort=e.date_modified&order=DESC).
On checkout I'm getting this error:
WARNING::556::There are no valid services available.
But I tried the same from and to address on the calculator on the fedex website and it gives me two services: International Priority and International Economy
This is the debug data I have:
Array
(
[WebAuthenticationDetail] => Array
(
[UserCredential] => Array
(
[Key] => REDACTED
[Password] => REDACTED
)
)
[ClientDetail] => Array
(
[AccountNumber] => REDACTED
[MeterNumber] => REDACTED
)
[TransactionDetail] => Array
(
[CustomerTransactionId] => *** Rate Request v9 using PHP ***
)
[Version] => Array
(
[ServiceId] => crs
[Major] => 9
[Intermediate] => 0
[Minor] => 0
)
[ReturnTransitAndCommit] => 1
[RequestedShipment] => Array
(
[DropoffType] => REQUEST_COURIER
[ShipTimestamp] => 2011-09-28T09:02:01+00:00
[PackagingType] => YOUR_PACKAGING
[TotalInsuredValue] => Array
(
[Amount] => 2000
[Currency] => EUR
)
[Shipper] => Array
(
[Address] => Array
(
[StreetLines] => Array
(
[0] =>
[1] =>
)
[City] => Ronchis
[StateOrProvinceCode] =>
[PostalCode] => 33050
[CountryCode] => IT
[Residential] => 1
)
)
[Recipient] => Array
(
[Address] => Array
(
[StreetLines] => Array
(
[0] =>
[1] =>
)
[City] => villach
[StateOrProvinceCode] =>
[PostalCode] => 9500
[CountryCode] => AT
[Residential] => 1
)
)
[ShippingChargesPayment] => Array
(
[PaymentType] => SENDER
[Payor] => Array
(
[AccountNumber] => 263150082
[CountryCode] => IT
)
)
[RateRequestTypes] => LIST
[PackageCount] => 1
[PackageDetailSpecified] => 1
[PackageDetail] => INDIVIDUAL_PACKAGES
[RequestedPackageLineItems] => Array
(
[0] => Array
(
[Weight] => Array
(
[Value] => 34
[Units] => KG
)
[Dimensions] => Array
(
[Length] => 48
[Width] => 53
[Height] => 122
[Units] => CM
)
)
)
)
)
----------
-- NUSOAP -- Array
(
[HighestSeverity] => WARNING
[Notifications] => Array
(
[Severity] => WARNING
[Source] => crs
[Code] => 556
[Message] => There are no valid services available.
[LocalizedMessage] => There are no valid services available.
)
[TransactionDetail] => Array
(
[CustomerTransactionId] => *** Rate Request v9 using PHP ***
)
[Version] => Array
(
[ServiceId] => crs
[Major] => 9
[Intermediate] => 0
[Minor] => 0
)
)
What should I do?
I just ran into this error, and it turned out that the issue was an invalid postal code. Double check that you are specifying the "Shipper" information correctly.
Also, if that doesn't work give the FedEx customer support phone number a try. We would not have figured this issue out without their help.
I was also having this issue .. but with Joomla, Virtuemart. Because the FedEx server is the same so may be my solution could help somebody else too..
Here are the main things what I fixed to fix this issue.
Product's Weight should be less than the limit if you've set any as Maximum Weight.
If you are using any packaging has more weight than FedEx's provided box i.e. 25KG BOX or 10KG box, then always use "Your Own packaging"
it's true, do keep an eye on ZIP===States (i was testing and put wrong state with different zip) And this ZIP should be added in "Shop's Address" because this is considered as FROM and the destination address as well.
Do note if products have added weights. LWH (Length, Width, Height).
Mine issue resolved after weeks of trouble! I wish somebody else could also resolve this issue if facing.
I was facing following error
"10 kg packaging box is **only** Available at FedEx World Service CenterĀ® locations!"
which was a big help to resolve the limitation i've set.
This issue happen when one of the bellow cases.
Country given is not associated with FedEx account.
Origin address is not real, Especially the post code.
The given packagingType is available in your country.
You need to provide a ServiceType. One of these:
EUROPE_FIRST_INTERNATIONAL_PRIORITY
FEDEX_1_DAY_FREIGHT
FEDEX_2_DAY
FEDEX_2_DAY_AM
FEDEX_2_DAY_FREIGHT
FEDEX_3_DAY_FREIGHT
FEDEX_EXPRESS_SAVER
FEDEX_FIRST_FREIGHT
FEDEX_FREIGHT_ECONOMY
FEDEX_FREIGHT_PRIORITY
FEDEX_GROUND
FIRST_OVERNIGHT
GROUND_HOME_DELIVERY
INTERNATIONAL_ECONOMY
INTERNATIONAL_ECONOMY_FREIGHT
INTERNATIONAL_FIRST
INTERNATIONAL_PRIORITY
INTERNATIONAL_PRIORITY_FREIGHT
PRIORITY_OVERNIGHT
SMART_POST
STANDARD_OVERNIGHT
Use it in the same level as the DropoffType
Make sure that you have the Zip Code set to required.
You can do that in System -> Localization -> Countries.
It is not required by default in opencart, and the fedex shipping system will not work without it.
This issue can also be caused by requesting insurance in a country that doesn't support it, such as Canada.
I also ran into this problem and the solution was trimming extra spaces from the end of the address, city & postal code. After that, all was well again.
I don't know why FedEx's API all of a sudden stopped accepting the extra spaces, but who knows...
In my case, this was caused by trying to ship internationally from the US to Italy, and having specified a SignatureOptionDetail of NO_SIGNATURE_REQUIRED. Changing this to SERVICE_DEFAULT fixed it.

Resources