A method for performing a lookup in a switching device of a packet switched network, where the lookup includes a plurality of distinct operations, each of which obtains a result and at least one of which includes a pointer to a next operation in a sequence of operations for the lookup, the method comprising: determining a first lookup operation in the sequence of operations to be executed, where the first lookup operation is selected from a group including a tree search, an index search, and a filter operation; executing the first lookup operation to obtain a result; determining if the result, obtained based on executing the first lookup operation, includes a pointer to a second lookup operation in the sequence of operations; when the result, obtained based on executing the first lookup operation, is determined to include a pointer to the second lookup operation, executing the second lookup operation indicated by the result, wherein the second lookup operation specifies a function to be executed during the execution of the second lookup operation, characterised in that: wherein the function is selected from a group comprising a management function, an accounting function, and a policing function, and wherein executing the second lookup operation includes: executing the function to obtain a result, where executing the function includes: determining when a packet should be sampled for further processing, wherein sampling refers to forwarding a copy or portion of the packet to an external system for the further processing, and including in the result, obtained based on executing the function, a designation that indicates that the packet is to be sampled; and when the result, obtained based on executing the first lookup operation, is not determined to include a pointer to a second lookup operation, terminating the lookup; and wherein the first lookup operation and the second lookup operation use a key included in the packet. determining a first lookup operation in the sequence of operations to be executed, where the first lookup operation is selected from a group including a tree search, an index search, and a filter operation; executing the first lookup operation to obtain a result; determining if the result, obtained based on executing the first lookup operation, includes a pointer to a second lookup operation in the sequence of operations; when the result, obtained based on executing the first lookup operation, is determined to include a pointer to the second lookup operation, executing the second lookup operation indicated by the result, wherein the second lookup operation specifies a function to be executed during the execution of the second lookup operation, characterised in that: wherein the function is selected from a group comprising a management function, an accounting function, and a policing function, and wherein executing the second lookup operation includes: executing the function to obtain a result, where executing the function includes: determining when a packet should be sampled for further processing, wherein sampling refers to forwarding a copy or portion of the packet to an external system for the further processing, and including in the result, obtained based on executing the function, a designation that indicates that the packet is to be sampled; and wherein the second lookup operation specifies a function to be executed during the execution of the second lookup operation, characterised in that: wherein the function is selected from a group comprising a management function, an accounting function, and a policing function, and wherein executing the second lookup operation includes: executing the function to obtain a result, where executing the function includes: determining when a packet should be sampled for further processing, wherein sampling refers to forwarding a copy or portion of the packet to an external system for the further processing, and including in the result, obtained based on executing the function, a designation that indicates that the packet is to be sampled; and wherein the function is selected from a group comprising a management function, an accounting function, and a policing function, and wherein executing the second lookup operation includes: executing the function to obtain a result, where executing the function includes: determining when a packet should be sampled for further processing, wherein sampling refers to forwarding a copy or portion of the packet to an external system for the further processing, and including in the result, obtained based on executing the function, a designation that indicates that the packet is to be sampled; and executing the function to obtain a result, where executing the function includes: determining when a packet should be sampled for further processing, wherein sampling refers to forwarding a copy or portion of the packet to an external system for the further processing, and including in the result, obtained based on executing the function, a designation that indicates that the packet is to be sampled; and determining when a packet should be sampled for further processing, wherein sampling refers to forwarding a copy or portion of the packet to an external system for the further processing, and including in the result, obtained based on executing the function, a designation that indicates that the packet is to be sampled; and when the result, obtained based on executing the first lookup operation, is not determined to include a pointer to a second lookup operation, terminating the lookup; and wherein the first lookup operation and the second lookup operation use a key included in the packet.